gotham icon indicating copy to clipboard operation
gotham copied to clipboard

HandlerError with body data

Open rp- opened this issue 3 years ago • 2 comments

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.

rp- avatar May 01 '21 20:05 rp-

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.

msrd0 avatar May 02 '21 00:05 msrd0

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.

rp- avatar May 02 '21 09:05 rp-