-
-
Couldn't load subscription status.
- Fork 411
Description
What is the problem this feature would solve?
I have an existing API that I want to create API specs for using the HttpApi module, before gradually implementing it using the HttpApiBuilder, phasing out its old implementation.
The API specs can be fully customised in what each endpoint responds with by using addSuccess and addError, except for one thing: The HttpApiDecodeError.
This means I'm unable to create an API spec to fully cover my existing API.
I posted this on Discord a while ago, but never got a response.
What is the feature you are proposing to solve the problem?
A setDecodeError method that takes a Schema<HttpApiDecodeError, T> so I can customize how those are encoded:
const HttpApiDecodeErrorFromMyWeirdValidationError =
Schema.transform(
MyWeirdValidationError,
HttpApiDecodeError.HttpApiDecodeError,
{ encode: (yours) => ({...}), decode: (mine) => ({...}) }
)
export default HttpApi.make('myApi')
.add(MyApiGroup)
.setDecodeError(HttpApiDecodeErrorFromMyWeirdValidationError) // <--- override
.addError(MyWeirdInternalServerError, { status: 500 })What alternatives have you considered?
Hacking the response with a middleware, and hacking the OpenAPI JSON object: #5367 (comment)