Skip to content

Commit

Permalink
Pass-through HttpError caught in multipart handler (#867)
Browse files Browse the repository at this point in the history
- Consumers of express-openapi-validator have access to the custom error
  types via exported object: error (e.g. error.BadRequest).
- If the multipart handler throws, for example from the multer storage
  engine, check whether the err instance is already an HttpError. If so,
  it can be passed-through as is. This is mostly useful for setting the
  HTTP status code.
  • Loading branch information
mdmower authored Nov 18, 2023
1 parent a9a3b0b commit 240c876
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/middlewares/openapi.multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function error(req: OpenApiRequest, err: Error): ValidationError {
: !unexpected
? new BadRequest({ path: req.path, message: err.message })
: new InternalServerError({ path: req.path, message: err.message });*/
} else if (err instanceof HttpError) {
return err;
} else {
// HACK
// TODO improve multer error handling
Expand Down

0 comments on commit 240c876

Please sign in to comment.