-
Notifications
You must be signed in to change notification settings - Fork 76
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
Returning error responses which don't fit the HttpErrorResponseBody structure #124
Comments
That sounds like a reasonable thing to do! I think there are a couple of approaches here:
|
Thanks for the reply! I didn't consider checking up the chain from From my end, I think the ability to return arbitrary status codes with a typed body would be good first-class functionality. It's a bit surprising how restricted the pre-built API is -- that isn't a problem, and is presumably a design goal. But it also means it's probably healthy to provide an escape hatch for those who need something outside of the guard rails. But then again, assuming the above works out, it evidently is possible for those who need it. |
I hear that. Yeah, we sometimes prefer a smaller Dropshot API to ensure consistent behavior across our various consumers. Still, the escape hatches are important, and if we're using them a lot, we'll first-class them, too. Closing because I think we've resolved this but please reopen if you run into trouble. |
I'm porting an existing server to Dropshot as a proof-of-concept.
It seems from the docs that the only way to return an error (i.e., 4xx or 5xx status code) from a route handler is to return an
HttpError
. Unfortunately, this seems to impose a specific structure on the returned body (HttpErrorResponseBody
). A custom implementation of theHttpTypedResponse
type would seem to be appropriate here, but that type appears to be un-exported.In my case, I have a "health" endpoint which returns the same health payload regardless of up/down status but uses the status code to indicate whether the service is healthy. I could also imagine arbitrary other cases where users might not want the prescribed structure of an
HttpError
.Is there a way to work around this? A particular type I can return which will get me both appropriate body typing for OpenAPI specs and a non-success status code? Am I missing something?
The text was updated successfully, but these errors were encountered: