Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding response status code #13

Open
itayAmza opened this issue Dec 17, 2021 · 3 comments
Open

Overriding response status code #13

itayAmza opened this issue Dec 17, 2021 · 3 comments

Comments

@itayAmza
Copy link

Hi @alexsteinerde,
How can I return response code other that 200 for specific scenarios (unauthorized etc)?
I've tried adding a custom error middleware but because RoutesBuilder status is always ok I it never uses it.

@alexsteinerde
Copy link
Owner

Hi,
this isn't supported at the moment. If you like you can create a PR for this.
Currently I don't have any specific ideas on how to implement that but it could probably be done by analyzing the returned GraphQLResult error array.

@alexsteinerde
Copy link
Owner

After a second thought I came up with an idea on how this could be implemented.
We could introduce a protocol that your custom errors would conform to. Then we could check on that new error type and extract the status code from that which would be returned as the response.

I created a separate branch for that: https://github.com/alexsteinerde/graphql-kit/compare/http-status-error

What do you think about that?

@itayAmza
Copy link
Author

Sorry for late response.
I liked your solution, I played with it a bit but eventually I felt like were ignoring GraphQL best practices, and other users in the future might miss the point and abuse it.
I tried to go for a high level solution here.
WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants