Skip to content

Commit 240c876

Browse files
authored
Pass-through HttpError caught in multipart handler (#867)
- 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.
1 parent a9a3b0b commit 240c876

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Diff for: src/middlewares/openapi.multipart.ts

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ function error(req: OpenApiRequest, err: Error): ValidationError {
127127
: !unexpected
128128
? new BadRequest({ path: req.path, message: err.message })
129129
: new InternalServerError({ path: req.path, message: err.message });*/
130+
} else if (err instanceof HttpError) {
131+
return err;
130132
} else {
131133
// HACK
132134
// TODO improve multer error handling

0 commit comments

Comments
 (0)