Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migrate): forward possible API error response to error thrown for non 2xx #6387

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Apr 16, 2024

Description

Currently, when running a migration and the server responds with a non-2xx status, the error details from response body (e.g. in case of 4xx) is not properly forwarded to the error thrown by the migration command. This causes otherwise helpful details to be omitted from the error output.

Before:

npx sanity migration run some-migration

Running migration "some-migration" in dry mode

Project id:  some-project-id
Dataset:     doesnt-exist
Error
    at assert2xx (<snip>/fetchStream.ts:21:17)
   //…

After:

npx sanity migration run some-migration

Running migration "some-migration" in dry mode

Project id:  some-project-id
Dataset:     doesnt-exist
HTTPError: Dataset not found: Dataset "doesnt-exist" not found for project ID "some-project-id"
    at assert2xx (<snip>/fetchStream.ts:21:17)
   //…

What to review

  • Originally we were reading the error message from error.description. Is it a fair assumption that was a mistake and that API errors never have a description field? If not, I'll add a fallback to description.
  • If receiving a non-2xx and we could not parse the response as JSON we were currently throwing a separate JSON parse error. I believe this would prevent any HTTP errors without a JSON-parseable body to be thrown as HTTP errors containing the status code and status message, so I've refactored this so we throw a HTTP error if we get a non-2xx and there's no JSON in the response body.

Testing

Unit tests added.

Notes for release

  • Improved error handling when running migration against invalid project configurations

@bjoerge bjoerge requested a review from a team as a code owner April 16, 2024 09:52
@bjoerge bjoerge requested review from jtpetty and removed request for a team April 16, 2024 09:52
Copy link

vercel bot commented Apr 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Apr 16, 2024 9:55am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 16, 2024 9:55am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Apr 16, 2024 9:55am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

Component Testing Report Updated Apr 16, 2024 10:00 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 30s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 5s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 24s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 12s 4 2 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 30s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 58s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 0s 18 0 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 11s 6 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 19s 9 0 0

Copy link
Contributor

@jtpetty jtpetty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bjoerge bjoerge added this pull request to the merge queue Apr 17, 2024
Merged via the queue into next with commit 9316475 Apr 17, 2024
37 checks passed
@bjoerge bjoerge deleted the sdx-1268 branch April 17, 2024 15:50
jordanl17 pushed a commit that referenced this pull request Apr 19, 2024
… non 2xx (#6387)

* test(migrate): add test cases for request error handling

* fix(migrate): forward possible API error response to error thrown in case of non 2xx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants