-
-
Notifications
You must be signed in to change notification settings - Fork 157
Guard against parsing non-JSON responses as JSON #8491
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
Open
iHiD
wants to merge
1
commit into
main
Choose a base branch
from
fix/8481
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,19 +94,25 @@ export const useErrorHandler = ( | |
|
|
||
| handler(new HandledError(defaultError.message)) | ||
| } else if (error instanceof Response) { | ||
| error | ||
| .clone() | ||
| .json() | ||
| .then((res: { error: APIError }) => { | ||
| handler(new HandledError(res.error.message)) | ||
| }) | ||
| .catch((e) => { | ||
| if (process.env.NODE_ENV == 'production') { | ||
| Sentry.captureException(e) | ||
| } | ||
|
|
||
| handler(new HandledError(defaultError.message)) | ||
| }) | ||
| const contentType = error.headers.get('Content-Type') | ||
| const isJson = | ||
| contentType && | ||
| (contentType.includes('application/json') || | ||
| contentType.includes('+json')) | ||
|
|
||
| if (isJson) { | ||
| error | ||
| .clone() | ||
| .json() | ||
| .then((res: { error: APIError }) => { | ||
| handler(new HandledError(res.error.message)) | ||
| }) | ||
| .catch(() => { | ||
| handler(new HandledError(defaultError.message)) | ||
| }) | ||
| } else { | ||
| handler(new HandledError(defaultError.message)) | ||
| } | ||
| } | ||
| }, [defaultError, error, handler]) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ export const CropFinishedStep = ({ | |
| /* TODO: (optional) Use our standard sendRequest library */ | ||
| return fetch(links.update, { body: formData, method: 'PATCH' }) | ||
| .then((response) => { | ||
| if (!response.ok) throw response | ||
| return response.json().then((json) => camelizeKeys(json)) | ||
| }) | ||
| .then((json) => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,10 @@ function patchTheme(theme: string, updateEndpoint?: string) { | |
| user_preferences: { theme }, | ||
| }), | ||
| }) | ||
| .then((res) => res.json()) | ||
| .then((res) => { | ||
| if (!res.ok) throw new Error('Failed to update theme') | ||
| return res.json() | ||
| }) | ||
| .catch((e) => | ||
| // eslint-disable-next-line no-console | ||
| console.error('Failed to update to accessibility-dark theme: ', e) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Client-side cross-site scripting High
Copilot Autofix
AI about 2 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.