UNPKG

1.02 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Custom error class used in unifile
5 */
6class UnifileError extends Error {
7 static get ENOTSUP() { return 'ENOTSUP'; }
8 static get EISDIR() { return 'EISDIR'; }
9 static get EACCES() { return 'EACCES'; }
10 static get EINVAL() { return 'EINVAL'; }
11 static get ENOENT() { return 'ENOENT'; }
12 static get EIO() { return 'EIO'; }
13
14 constructor(code, message, ...params) {
15 super(message, ...params);
16 this.name = 'UnifileError';
17 this.code = code;
18 // use defineProperty in order to send the message field
19 // when using express res.send(err)
20 Object.defineProperty(this, 'message', {
21 value: message,
22 writable: false,
23 enumerable: true,
24 configurable: true
25 });
26 }
27}
28
29/**
30 * a different error name to be able to
31 * differenciate batch errors from other errors
32 */
33class BatchError extends UnifileError {
34 constructor(code, message, ...args) {
35 super(code, message, ...args);
36 this.name = 'BatchError';
37 }
38}
39
40module.exports = {
41 UnifileError: UnifileError,
42 BatchError: BatchError
43};
44