diff --git a/README.md b/README.md index 6bf71dbe..f404040d 100644 --- a/README.md +++ b/README.md @@ -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') { @@ -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; diff --git a/examples/with-http.js b/examples/with-http.js index b19b0712..ef12d066 100644 --- a/examples/with-http.js +++ b/examples/with-http.js @@ -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