question-mark
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.

Status code on validation fail

See original GitHub issue

Hello, I found such bug in returned status code when using Apollo (even in the example in this repository).

If some validation failed Apollo return status 500. I would say status code should be 400 because it is client error, not server error.

I was digging a little bit deeper. In my opinion the problem is, that you are throwing GraphQlError in error cases. But in all examples from graphql recommended in Apollo docs, they are calling ValidationContext.reportError(new GraphQlError(...) instead.

I can make pull request and we can discuss it more then.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
c3b5awcommented, Sep 30, 2022

Hello, I see that it was merged already. Everything is working just fine, just one small issue. I have to install @escape.tech/graphql-armor-types separately. Otherwise typescript control fail on Cannot find module '@escape.tech/graphql-armor-types' or its corresponding type declarations.

Great catch, pushing a patch version!

1reaction
c3b5awcommented, Sep 27, 2022

#162, should introduce ability to override the error behavior.

The trade-off and how-to must be documented as well.

@PatizonP I will let you know as soon as this is done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which status code should I use for failed validations or invalid ...
I recommend using 422 UNPROCESSABLE ENTITY for validation errors. I give a longer explanation of 4xx codes here. Share.
Read more >
HTTP status codes - Oracle Help Center
HTTP status codes · 200: "OK" · 201: "Success" · 204: "Success" · 301: "Login required" · 304: "Not Modified" · 400: "There...
Read more >
Which HTTP code is best suited for validation errors - Quora
HTTP Error 400 or 400 Bad Request Error is one of the HTTP Error status code which means the request was malformed or...
Read more >
What http error to return in case of validation and business ...
The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. In this case, you might be...
Read more >
HTTP Status Codes - REST API Tutorial
This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found