-
-
Notifications
You must be signed in to change notification settings - Fork 680
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
Distinguish error types #317
Comments
As a side note: try-clauses are not good to wrap any production code in as node apparently runs slower (at least so I've heard) |
Have a look #686 import formidable, {errors as formidableErrors} from 'formidable';
const form = formidable({ multiples: true });
form.parse(req, (err, fields, files) => {
if (err) {
// check for a very specific error
if (err.code === formidableErrors.maxFieldsExceeded) {
}
console.error(err);
// nice error message and httpCode
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
res.end(String(err));
return;
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ fields, files }, null, 2));
}); |
This answered my question as well, I know this has been mentioned in the docs too where it says:
But in my opinion it's not clear enough as this example by you (@GrosSacASac ), so maybe adding it to the documentation too is not a bad idea. |
If a user posts content with a bad content-type or otherwise invalid request, I would like to provide a decent error message back.
I'm currently doing this by wrapping code using Formidable in a try-clause, which works, but also prevents any other lower level error in reaching the surface and getting properly logged.
How should I distinguish these operational errors from others?
Maybe Formidable could sub class
Error
and expose it's error class for use in something likee instanceof formidable.Error
? That would be nice to someone using bluebird.The text was updated successfully, but these errors were encountered: