You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we want to use a custom error (like the planned OpenPaymentsServer error in Rafiki) this prevents us from writing a general error error handler at the beginning of the middleware chain, since this middleware will always throw ctx.throw(500) for something other than a Koa.HttpError (and have a busy console.error log as well, without control over it).
By throwing a custom error instead of a ctx.throw, we can directly determine whether the particular Koa error came from this validation middleware or not, allowing us to be more explicit in how we handle the error and how we log the contents of the error.
Todos
Have the OpenAPI middleware throw a custom error (e.g. OpenAPIValidatorMiddlewareError)
The text was updated successfully, but these errors were encountered:
Context
While working on
in Rafiki, I discovered that the OpenAPI validator middleware uses the
ctx.throw
method directly when handling errors:open-payments/packages/openapi/src/middleware.ts
Lines 29 to 38 in d365729
If we want to use a custom error (like the planned
OpenPaymentsServer
error in Rafiki) this prevents us from writing a general error error handler at the beginning of the middleware chain, since this middleware will always throwctx.throw(500)
for something other than a Koa.HttpError (and have a busyconsole.error
log as well, without control over it).By throwing a custom error instead of a
ctx.throw
, we can directly determine whether the particular Koa error came from this validation middleware or not, allowing us to be more explicit in how we handle the error and how we log the contents of the error.Todos
OpenAPIValidatorMiddlewareError
)The text was updated successfully, but these errors were encountered: