Fix apiFetch error response not being parsed when using fetchAllMiddleware
#48703
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.
What?
It fixes an issue with the
apiFetch, which is not parsing the response error when using thefetchAllMiddleware.Notice that it's not ready to be merged because it could cause backward compatibility problems. I didn't have any good idea so far to keep it working with existing implementations parsing the error manually for this case. Any ideas?
Why?
When using the
apiFetch, we need to parse the error JSON manually if we have aper_page=-1in the path. See the problem with more details by running:By default, it shouldn't be needed, because the
parseoption istrueand should parse the JSON for us.How?
It was skipping the parse in case of error because it's forcing
parse: falseand parsing it later only in case of success. It fixes it by catching the error and parsing it too through theparseAndThrowError.Testing Instructions
Use the following snippet, and make sure the error is parsed.