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

HandlerError with body data #542

Open
rp- opened this issue May 1, 2021 · 2 comments
Open

HandlerError with body data #542

rp- opened this issue May 1, 2021 · 2 comments

Comments

@rp-
Copy link

rp- commented May 1, 2021

Maybe this should be done different, but I would assume that I can additionally to modify the status_code of the HandlerError also add body data.
My use-case would be e.g.: parsing JSON data from the request and if there is a syntax error return the error message from serde(as body) with an UNPROCESSABLE_ENTITY status code.

@msrd0
Copy link
Member

msrd0 commented May 2, 2021

It is not possible to attach any data except for the status code to a HandlerError. I don't believe that a HandlerError should be upgraded to full response creation abilities (this was suggested before, e.g. in #529). However, it might make sense to include the error message (since every Error implements Display anyways) in the created error response. It sounds like that would cover your use case.

@rp-
Copy link
Author

rp- commented May 2, 2021

Thanks, reading through #529 gave me a better picture on the design choice of gotham here.
I guess I have to create a more flexible way for error returns anyway, so I'll probably not use HandlerError for that, it would be just nice to use ? in most situations without wrapping the error in a normal response.

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

No branches or pull requests

2 participants