fix(error): respect accept: text/html
request header
#1921
Merged
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.
Requests made with the Fetch API cause
sec-fetch-mode
to be set, leading to these requests to be identified as JSON requests. The default error handler uses isJsonRequest to render errors. If a request were to set the Accept header to "text/html" the response should be HTML as well.🔗 Linked issue
#1919
❓ Type of change
📚 Description
isJsonRequest
is modified, its only usage (within nitro) is by the default event handler to determine when to serialize errors as HTML or JSON.This change is needed because requests made with the Fetch API automatically get the
sec-fetch-mode=cors
header. This header is one of the conditions by whichisJsonRequest
function identifies JSON, but the header has no such meaning as far as the standard is concerned.More importantly, the function does not provide any means to enforce an HTML response (for
isJsonRequest
to return false) when these fallback detections are used.Resolves #1919
📝 Checklist