Skip to content

Commit

Permalink
doc: add note on how to use formidableErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosSacASac committed Oct 9, 2022
1 parent 8e99cfb commit e060e3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Parse an incoming file upload, with the

```js
import http from 'node:http';
import formidable from 'formidable';
import formidable, {errors as formidableErrors} from 'formidable';

const server = http.createServer((req, res) => {
if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') {
Expand All @@ -107,6 +107,10 @@ const server = http.createServer((req, res) => {

form.parse(req, (err, fields, files) => {
if (err) {
// example to check for a very specific error
if (err.code === formidableErrors.maxFieldsExceeded) {

}
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
res.end(String(err));
return;
Expand Down
3 changes: 1 addition & 2 deletions examples/with-http.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import http from 'node:http';
import slugify from '@sindresorhus/slugify';
import formidable from '../src/index.js';

import formidable, {errors as formidableErrors} from '../src/index.js';

const server = http.createServer((req, res) => {
// handle common internet errors
Expand Down

0 comments on commit e060e3f

Please sign in to comment.