-
-
Notifications
You must be signed in to change notification settings - Fork 130
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: unify server error response across interceptors #555
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,31 +99,30 @@ export function createXMLHttpRequestProxy({ | |
return | ||
} | ||
|
||
// Treat unhandled exceptions in the "request" listener | ||
// as 500 server errors. | ||
xhrRequestController.respondWith( | ||
new Response( | ||
JSON.stringify({ | ||
name: resolverResult.error.name, | ||
message: resolverResult.error.message, | ||
stack: resolverResult.error.stack, | ||
}), | ||
{ | ||
status: 500, | ||
statusText: 'Unhandled Exception', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
if (resolverResult.error instanceof Error) { | ||
// Treat unhandled exceptions in the "request" listener | ||
// as 500 server errors. | ||
xhrRequestController.respondWith( | ||
new Response( | ||
JSON.stringify({ | ||
name: resolverResult.error.name, | ||
message: resolverResult.error.message, | ||
stack: resolverResult.error.stack, | ||
}), | ||
{ | ||
status: 500, | ||
statusText: 'Unhandled Exception', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
) | ||
) | ||
) | ||
return | ||
} | ||
|
||
/** | ||
* @todo Consider forwarding this error to the stderr as well | ||
* since not all consumers are expecting to handle errors. | ||
* If they don't, this error will be swallowed. | ||
*/ | ||
// xhrRequestController.errorWith(resolverResult.error) | ||
// Otherwise, error the request with the thrown data. | ||
xhrRequestController.errorWith(resolverResult.error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The argument for translating any other (non-error) data to request errors is a bit weaker. There should be a way to trigger request errors. Now that I think about it, we do have that way! It's this: request.respondWith(Response.error()) This translates to a request error across different clients. I think we need to remove non-error handling changes and treat non-errors as 500 responses anyway. So the three cases become this:
I think this makes the most sense. |
||
return | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument of treating exceptions as 500 responses is good, see: #516. TL;DR, if exceptions are preserved, they will be handled by the higher request client. Not only different clients handle those exceptions differently, but that harms the observability of the thrown error.
I also think that treating unhandled exceptions as 500 responses is more similar to the actual server, and you write these request listeners from the server's respective.