From 240c87669c0ec550fe64dfd5c278f89f0fd4effb Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Fri, 17 Nov 2023 17:22:05 -0800 Subject: [PATCH] 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. --- src/middlewares/openapi.multipart.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/middlewares/openapi.multipart.ts b/src/middlewares/openapi.multipart.ts index 52a071bf..5871ccce 100644 --- a/src/middlewares/openapi.multipart.ts +++ b/src/middlewares/openapi.multipart.ts @@ -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