gotham-rs / gotham

A flexible web framework that promotes stability, safety, security and speed.

Home Page:https://gotham.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HandlerError with body data

rp- opened this issue · 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.

commented

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.

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.