expressjs / multer

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

Update Docs: Error: read ECONNRESET thrown during test using supertest, mocha but works fine while using postman. #1240

Closed sebakthapa closed 9 months ago

sebakthapa commented 9 months ago

ECONNRESET during test only

    Error while testing invalid file upload Error: read ECONNRESET
        at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
      errno: -4077,
      code: 'ECONNRESET',
      syscall: 'read',
      response: undefined
    }

What is causing the error?

One of the reason why this error occurs during test but not on other methods is related to how we call cb() of fileFilter option/function when we are rejecting certain file.

The above error was thrown when fileFilter is passed and inside it the callback is returned as:

 cb(new Error("some error msg");

but not when callback is returned as:

 cb(null, false);

What is missing in the documentation?

The right way to pass cb() for custom error is the following:

cb(null, false, new Error("some error msg"))

What should be added in the documentation and where?

// If you want to reject a file with custom error:
cb(null, false, new Error("some error msg"))

The above line should be appended in the fileFilter option description

It would be better to append it below the line which shows how to reject a file.

sebakthapa commented 9 months ago

This contains misinformation as there is not third parameter for the cb() function.