kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

Quick question: [openapi-request-validator]: Is a better error handling possible? #790

Open Fridious opened 2 years ago

Fridious commented 2 years ago

initialize({ ... errorMiddleware: (err, req, res, next) => { ... } });

My project is configured with typescipt and open-api 3 specification. I try to optimize my error handling, but the err parameter in the errorMiddleware is a plain js object. Because of this, it is very hard or partly not possible to know, if the error is a validation error from openapi or another error. It would be better, if the err has a specific type and not only is a object.

The type checking of the err could be something like this: if (err instanceOf ValidationError) {}

I found this on your project: https://github.com/kogosoftwarellc/open-api/blob/master/packages/openapi-request-validator/index.ts#L382 , I think this can be optimized there.