Skip to content

Commit e060e3f

Browse files
committed
doc: add note on how to use formidableErrors
1 parent 8e99cfb commit e060e3f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Parse an incoming file upload, with the
9898

9999
```js
100100
import http from 'node:http';
101-
import formidable from 'formidable';
101+
import formidable, {errors as formidableErrors} from 'formidable';
102102

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

108108
form.parse(req, (err, fields, files) => {
109109
if (err) {
110+
// example to check for a very specific error
111+
if (err.code === formidableErrors.maxFieldsExceeded) {
112+
113+
}
110114
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
111115
res.end(String(err));
112116
return;

examples/with-http.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import http from 'node:http';
22
import slugify from '@sindresorhus/slugify';
3-
import formidable from '../src/index.js';
4-
3+
import formidable, {errors as formidableErrors} from '../src/index.js';
54

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

0 commit comments

Comments
 (0)