-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
TypeScript - Unable to access FormidableError on formidable.errors #972
Comments
Where did you see that way of using this variable ? |
Nowhere, in retrospect I don't know if this is even the right way to do it at all 😅 |
formidable.errors is not the same as FormidableErrors. https://github.com/node-formidable/formidable/blob/master/src/FormidableError.js or As you can see all errors have a httpCode So you could do the following
|
I don't know how to apply that to my example @GrosSacASac. import formidable, {errors as FormidableErrors} from 'formidable';
....
form.parse(req, async (err, fields, files) => {
if (err) {
if (err instanceof FormidableErrors.FormidableError) {
if (err.httpCode !== undefined) {
return res.status(err.httpCode).send(err.message);
}
}
}
}); But get this error:
|
if (err instanceof FormidableErrors.default) |
I'm doing this successfully with the following: import { errors as formidableErrors } from 'formidable';
// ...
if e (instanceof formidableErrors.FormidableError) But I'm on v2 of formidable, not sure if that matters. |
I'm doing this to verify the error type in v3.5.2 import formidable, { errors as formidableErrors } from 'formidable';
try {
[fields, files] = await form.parse(event.node.req);
} catch (error) {
if (error && typeof error === 'object' && 'code' in error) {
if (error.code === formidableErrors.biggerThanMaxFileSize)
throw new BadRequestError('File exceeds the maximum allowed size of 5MB');
}
throw new UnexpectedError();
} |
Support plan
Context
What are you trying to achieve or the steps to reproduce?
I'd like to access the FormidableError object when I'm throwing an error, this is my use case:
In postman I'm passing multipart formdata, where I purposely input a file above the MAX_FILE_SIZE, the error is thrown properly, but I just seem unable to get the FormidableError object.
What was the result you got?
TypeError: Cannot read properties of undefined (reading 'FormidableError')
What result did you expect?
That the above use case works
The text was updated successfully, but these errors were encountered: