expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.61k stars 1.06k forks source link

Could Busboy errors be wrapped? #1049

Open benasher44 opened 2 years ago

benasher44 commented 2 years ago

In make-middleware.js, creating a new Busboy is wrapped in a try/catch. However, those errors are passed straight to next, which makes them hard to operate on. For example, Busboy throws an error immediately if the multipart boundary is missing. I'd like to turn this into a 4xx error, but right now it's a 5xx, since we can't do instanceof MulterError. It would be great if these errors were wrapped in a MulterError. In fact, I think that is maybe the only error that Busboy throws during init, in which case it could even get its own error code.

LinusU commented 2 years ago

Sounds like a good idea 👍

I was planning on looking over all the errors in the 2.x branch before releasing, since I think that they could be improved!