File tree 2 files changed +6
-3
lines changed
2 files changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ Parse an incoming file upload, with the
98
98
99
99
``` js
100
100
import http from ' node:http' ;
101
- import formidable from ' formidable' ;
101
+ import formidable , { errors as formidableErrors } from ' formidable' ;
102
102
103
103
const server = http .createServer ((req , res ) => {
104
104
if (req .url === ' /api/upload' && req .method .toLowerCase () === ' post' ) {
@@ -107,6 +107,10 @@ const server = http.createServer((req, res) => {
107
107
108
108
form .parse (req, (err , fields , files ) => {
109
109
if (err) {
110
+ // example to check for a very specific error
111
+ if (err .code === formidableErrors .maxFieldsExceeded ) {
112
+
113
+ }
110
114
res .writeHead (err .httpCode || 400 , { ' Content-Type' : ' text/plain' });
111
115
res .end (String (err));
112
116
return ;
Original file line number Diff line number Diff line change 1
1
import http from 'node:http' ;
2
2
import slugify from '@sindresorhus/slugify' ;
3
- import formidable from '../src/index.js' ;
4
-
3
+ import formidable , { errors as formidableErrors } from '../src/index.js' ;
5
4
6
5
const server = http . createServer ( ( req , res ) => {
7
6
// handle common internet errors
You can’t perform that action at this time.
0 commit comments