Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Response headers from error should be application/json

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

colthreepvcommented, Apr 11, 2016

Order of middleware is relevant, express-middleware basically calls a next(err) with err 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:

silverlight513commented, Apr 10, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found