Response headers from error should be application/json
See original GitHub issueThe response of the error given by express-validation is text/html; charset=utf-8
when it should be application/json; charset=utf-8
. Because it is text/html responses given back are parsed as below:
{"status":400,"statusText":"Bad Request","errors":[{"field":"content-type","location":"headers","messages":["\"content-type\" must be one of [application/json;charset=UTF-8]"],"types":["any.allowOnly"]}]}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Error response body format from a request with specific ...
A HTTP server is free to disregard the Accept header if none of the formats are available. Given that there's not really a...
Read more >The application/problem+json Content-Type - SymfonyCasts
... API error responses should look. Our response has type, title, and errors fields. ... And the "Content-Type" header should be "application/problem+json".
Read more >Missing header "Content-Type: application/json" in response ...
Clients have to parse the response content for errors. It contains an error object with the error message in case an error occurred....
Read more >Content-Type / Accept header error responses - JSON API
Hi there! I'm having a hard time interpreting the following Server Responsibilities: Servers MUST respond with a 415 Unsupported Media Type ...
Read more >Setting Content-Type for Error Response
Using TIBCO API Exchange Gateway, you can set the Content-Type for the error message if the Content-Type is not set in the HTTP...
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 FreeTop 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
Top GitHub Comments
Order of middleware is relevant, express-middleware basically calls a
next(err)
witherr
being the JSON error.So the next middleware receives this object, if there is not a next middleware in the chain of
/users
then it refers to the “global” chain, but it has to be defined after it.It is a tricky implementation for newcomers, but it’s not an express design, it is based off Ruby on Rails (afaik)
PS: just google “middleware pattern” and have a nice read :neckbeard:
Yup, just tested it and that is what the issue is. Is there a reason why the order of such a thing would cause this to happen in express? Sorry, I’m extremely new to backend JS.