Receiving Custom error messages from fetch
See original GitHub issueCouldn’t receive custom error messages that is responded by express server
when I use fetch
, however jQuery.ajax.fail()
could receive it
http://expressjs.com/en/api.html#res.send http://expressjs.com/en/api.html#res.json
Still I get the default statusText in response
For example, res.status(400).send({ message: ‘Password reset token is invalid or has expired’ }); I get statusText=Bad request and I don’t receive message
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Javascript fetch api use custom error message - Stack Overflow
So I want to use the response body text as a the error. I tried different ways, but I can't get the response...
Read more >Fetch error message javascript - MailSlurp
When using Javascript fetch to make HTTP requests an exception is thrown for any response with a code of 400 or more. This...
Read more >Fetch - Error Handling for Failed HTTP Responses and ...
A quick example of how to handle both network errors and HTTP errors (4xx or 5xx) for fetch requests in a single catch...
Read more >Handling Failed HTTP Responses With fetch() - TJ VanToll
Per MDN, the fetch() API only rejects a promise when a “network error is encountered, although this usually means permissions issues or similar....
Read more >Error handling while using native fetch API in JavaScript
First lets see, without handling errors,. fetch(url) .then(response => ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Express does not provide an API for this because not all of the supported Node.js versions of Express support this functionality, and it’s not recommended you do this, because your user may have a proxy between them and your server that assumes the status message is not custom, breaking your expectations in the browser.
If you really want to do this, you’ll need to use the raw Node.js directly: https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_response_statusmessage and be using Node.js 0.12+ and have no intermediate proxies between your Node.js server and the browser that rewrite that line (it’s very common for that to happen, which is another reason we don’t even bother to offer an Express API).
You use Node.js APIs in Express directly:
Closing to move the conversation to the support forum.