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

Allow overwrite function methodNotAllowedHandler #101

Closed
ivoszz opened this issue Oct 31, 2016 · 6 comments
Closed

Allow overwrite function methodNotAllowedHandler #101

ivoszz opened this issue Oct 31, 2016 · 6 comments

Comments

@ivoszz
Copy link

ivoszz commented Oct 31, 2016

I am just starting to use your project which seems excellent to me, but got into trouble with hard coded methodNotAllowedHandler function. I have to return JSON object on every error (like in JSON API spec) and I am not able to specify my own response to this error. Or can you suggest any solution to this? Thanks.

@pkieltyka
Copy link
Member

hey @ivoszz I see, potentially I can put a MethodNotAllowedHandler http.Handler on the chi.Mux and let you set it there. That will work but I need to check the interaction with subrouters.

@pkieltyka
Copy link
Member

@ivoszz I was just checking into this, and it seems the current methodNotAllowedHandler just returns 405 with an empty body, so it should be valid to the response of your json handler

@ivoszz
Copy link
Author

ivoszz commented Nov 8, 2016

hey @pkieltyka you are right. The body is empty but still marked as text/html and this doesn't solve the problem of JSON api. text/html is hard coded and cannot be changed even when there are Accept: application/json or application/vnd.api+json in request header. The header Allow is also not generated (and cannot be) which is against the spec:
"The origin server MUST generate an Allow header field in a 405 response containing a list of the target resource's currently supported methods."
The possibility of redefining methodNotAllowedHandler will be sufficient.

@pkieltyka
Copy link
Member

got it, good points

@ivoszz
Copy link
Author

ivoszz commented Nov 24, 2016

I would like to thank you for your effort.

@pkieltyka
Copy link
Member

:) no prob

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