Skip to content

Commit

Permalink
Pass-through HttpError caught in multipart handler
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 and mdmower-csnw committed Oct 20, 2023
1 parent bb8d6b8 commit 40a5671
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 40a5671

Please sign in to comment.