-
Notifications
You must be signed in to change notification settings - Fork 21
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
No codec to decode status 400 errors using superagent-wrapper+express-wrapper #165
Comments
Would having |
What would the What if you define an error codec that is adhered to when sending out an error from the express-wrapper's request decoding and just export that codec? An HttpRoute could by default use that error codec for the 400 status, leaving it up to the caller if they want to redefine the 400 response type by taking a union the existing codec with another, to return 400's that fit their specific use case? Superagent-wrapper would just use the 400 codec defined in the httproute as it does now. As of right now, basically every route has to look like this:
edit: on second thought you may not want to couple io-ts-http with express-wrapper, so perhaps there is an argument for an express-wrapper specific |
Agreed. One missing feature for API specs that could be nice is a way to specify a top-level set of responses that would apply to all routes so then they don't need to be tacked on to every route definition. Then, for example, a service could specify a general 500 error type in one spot. Then, with this, io-ts-http itself could specify a basic decode error type, and express wrapper can just import and use that. Do you think that would work? |
nailed it @bitgopatmcl |
When using
superagent-wrapper
in conjunction with a service built onexpress-wrapper
, a 400 error sent by theexpress-wrapper
leads tosuperagent-wrapper
failing to decode (usingdecodeExpecting
) if there is no codec defined for a 400 error response.It seems like we need a default error codec for the 400 status, because if the request is intercepted and rejected before the defined handler can get ahold of it, then the dev has no referential definition or control of the
express-wrapper
defined error message coming from request decoding errors which cause 400s.If the handler returns a 400 under certain circumstances, then that is under the dev's control and can be defined in the
HttpRoute
definition, but it could potentially conflict with the error response type returned by the express-wrapper, so a default error codec is also not the best solution. I don't have a better suggestion right now, but will think about it...The text was updated successfully, but these errors were encountered: