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.

Custom http status code response

See original GitHub issue

We are used to return different status codes depending on the error, e.g. 401, 404, 500, etc. Is it recommended to do this in GraphQL? If so, how to do that in express-graphql?

Thanks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
brunolemoscommented, Jul 27, 2016

Got it. Let’s say everything runs fine, but one query or one field returns null because of lack of permission.

Would you recommend returning an error saying why that query returned null? Or let it fail silently? I’m thinking of the format:

{ 
    statusCode: 501,
    field: "secretField",
    message: "Not authorized"
}
1reaction
helfercommented, Jul 27, 2016

@brunolemos That depends on whether the clients need to know (and do something with) the error. If they don’t need to know, then you shouldn’t return it. As for how to return it, you can just throw an error in the resolver, and let GraphQL.js include that in the response. Errors now also include a path, so it automatically tells you which field in the response was affected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can we create custom HTTP Status codes? - Stack Overflow
Yes you can add custom error codes. If possible use codes that already exist though, and if you are declaring ...
Read more >
Customize HTTP Responses | Documentation
ServiceStack provides multiple ways to customize your services HTTP response. Each option gives you complete control of the final HTTP Response that's returned ......
Read more >
List of HTTP status codes - Wikipedia
This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are ... Custom error pages · List of FTP...
Read more >
How to return a custom HTTP status code using WebAPI 2
This post will give you an example on how to return such a custom HTTP code. Have a look here for the natively...
Read more >
Defining Custom HTTP Response Status Codes
You can define custom HTTP response codes (in addition to the standard ones defined by the <HTTP 1.1 specification in RFC #2616>) that...
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