-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultipartError.js
42 lines (34 loc) · 978 Bytes
/
MultipartError.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const errorMessages = {
BAD_CONTENT_TYPE: 'Unsupported content type: ',
LIMIT_FIELD_COUNT: 'Too many fields',
LIMIT_FIELD_NAME: 'Field name too long',
LIMIT_FIELD_VALUE: 'Field value too long',
LIMIT_FILE_COUNT: 'Too many files',
LIMIT_FILE_SIZE: 'File too large',
LIMIT_PART_COUNT: 'Too many parts',
MISSING_FILE: 'Expected file field missing',
UNEXPECTED_FILE: 'Unexpected file field',
};
class MultipartError extends Error {
constructor(code, field) {
super(errorMessages[code]);
this.code = code;
if (code === 'BAD_CONTENT_TYPE') {
this.message += field; // field is the Content-Type header
this.status = 415;
return;
}
this.status = 400;
if (field !== undefined) {
this.field = field;
}
}
}
Object.defineProperty(MultipartError.prototype, 'name', {
value: MultipartError.name,
writable: true,
enumerable: false,
configurable: true,
});
module.exports = MultipartError;