-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request not finish when recieve an error #1247
Comments
@pullmann4rent I don't see anything obvious in the code. Multer calls the callback with an Error object can you see in your code which callback is getting that error object? |
"I'm facing the same issue. It happens when the multipart/form-data field contains an expected object with a different name. If I set it as 'file' and send it as 'item,' it will respond that it doesn't exist. The problem is that it sends a 500 error to the server and gets stuck in a loop. If I use multer's handleError, the error will be caught only once and the entire system will be stuck until a restart is necessary." |
Can we get a test case to reproduce? |
To fix the problem, I had to change upload.array to upload.any and do the validations internally 1.) The upload must be a multer.array('name', X). X can be any number 2.) In the request, enter a name other than "name". In other words, if I'm creating an api and the user uses a name other than the one required, the multer triggers the error and gets stuck. The solution is to restart the application. |
How does the user submit a different name other than the one required? |
I was making an image upload API for AWS S3 that accepts an array of fields of type 'multipart/form-data'. However, in my request I expect the field to be file, that is, a file array. If the user makes a mistake in the field and sends files, the multer gives an error 500 and warns "Unexpected field". If I use multer's handleError, I can catch the exception and send a custom error, but it stays in an infinite loop until the application crashes |
Is the user typing in a textbox the word "files"? Is this test case the same scenario as yours? |
Thank you for the additional information. It looks like there is a unit test for the unexpected field name situation. My current guess is that the "looping" behavior is caused by additional code and how it interacts with the request/response handling code. Would you be able to post the code that's handling errors? |
Inside my try cath there is my upload logic.
The problem is when the multer error occurs. I can give the 403 error, but it will be stuck in a loop waiting for request. To solve the problem, I replaced the array with any, and inside I did the logic of going through the array and seeing if it was the correct field, giving my custom error without crashing the app |
Can you try "using" the error handler after the |
I use multer for uploading files and if I upload an unexisting file or with a different file name then I get this
MulterError: Unexpected field
This is good that I catch the error but I can not send anymore request until I restart. Why ?
I use all of my files try catch and when I get an error I never got this problem. Only when it goes to my custom error handler:
And here is my custom error handler
The text was updated successfully, but these errors were encountered: