Comments (9)
That's because errors
export named variables with "error codes", not directly the error class.
That's a good point, we'll fix it. I think you can access the class on errors.default
.
from formidable.
Where did you see that way of using this variable ?
from formidable.
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 😅
from formidable.
That's because
errors
export named variables with "error codes", not directly the error class.That's a good point, we'll fix it. I think you can access the class on
errors.default
.
That doesn't seem to work 😔
from formidable.
import formidable, {errors as FormidableErrors} from 'formidable';
console.log(FormidableErrors.default);
formidable.errors is not the same as FormidableErrors.
The way you import is critical here
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
if (err.httpCode !== undefined)
from formidable.
I don't know how to apply that to my example @GrosSacASac.
I've tried this:
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:
file:///root/easyrate/easyrate-backend/js/routes/user.js:283
if (err instanceof FormidableErrors.FormidableError) {
^
TypeError: Right-hand side of 'instanceof' is not an object
at file:///root/easyrate/easyrate-backend/js/routes/user.js:283:21
at zalgoSafe (/root/easyrate/easyrate-backend/node_modules/dezalgo/dezalgo.js:20:10)
at f (/root/easyrate/easyrate-backend/node_modules/once/once.js:25:25)
at IncomingForm.<anonymous> (file:///root/easyrate/easyrate-backend/node_modules/formidable/src/Formidable.js:225:7)
at IncomingForm.emit (node:events:519:28)
at IncomingForm._error (file:///root/easyrate/easyrate-backend/node_modules/formidable/src/Formidable.js:495:10)
at Stream.<anonymous> (file:///root/easyrate/easyrate-backend/node_modules/formidable/src/Formidable.js:385:14)
at Stream.emit (node:events:519:28)
at MultipartParser.dataPropagation (file:///root/easyrate/easyrate-backend/node_modules/formidable/src/plugins/multipart.js:103:22)
at MultipartParser.emit (node:events:531:35)
Node.js v21.7.1
import formidable, {errors as FormidableErrors} from 'formidable'; console.log(FormidableErrors.default);
formidable.errors is not the same as FormidableErrors. The way you import is critical here
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
if (err.httpCode !== undefined)
from formidable.
if (err instanceof FormidableErrors.default)
from formidable.
That doesn't work either
I have imported like so:
import formidable, {errors as FormidableErrors} from 'formidable';
from formidable.
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.
from formidable.
Related Issues (20)
- TS Options Type Definition missing createDirsFromUploads HOT 1
- Attach fields to req.body and files to req.files like multer HOT 1
- [deps] Check for breaking changes in Dependabot PRs HOT 1
- @cunha-ambisis you should create a new form on each request (inside app.use) HOT 1
- Since V3 I get "formidable is not a function" - using require not import HOT 12
- Make multipart parser less dependent on NodeJS HOT 2
- Regression in Formidable v3, which can crash a server HOT 7
- form.parse's Promise never resolves in tests HOT 8
- Hexoid Error (?)
- Buffer usage HOT 2
- Files parsed by `IncomingForm().parse` are not automatically cleaned up or deleted. HOT 6
- firstValues export in index HOT 4
- Build giving the error in `cloudflare-pages` preset HOT 2
- maxFileSize not working as it should HOT 1
- Convert 'firstValues' helper into an option for Formidable constructor. HOT 2
- Support the contentType of multipart field. HOT 2
- VERSION_NOTES.md is misleading
- Engines missing in `package.json` and wrong version of Node.js supported listed in README
- How to wait for the result of writeHandler in a formidable file upload request? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formidable.