-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy patherrors.js
71 lines (63 loc) · 1.3 KB
/
errors.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
/**
* Lightweight web framework for your serverless applications
* @author Jeremy Daly <[email protected]>
* @license MIT
*/
/*
Custom error types
*/
class RouteError extends Error {
constructor(message, path) {
super(message);
this.name = 'RouteError';
this.path = path;
}
}
class MethodError extends Error {
constructor(message, method, path) {
super(message);
this.name = 'MethodError';
this.method = method;
this.path = path;
}
}
class ConfigurationError extends Error {
constructor(message) {
super(message);
this.name = 'ConfigurationError';
}
}
class ResponseError extends Error {
constructor(message, code) {
super(message);
this.name = 'ResponseError';
this.code = code;
}
}
class ApiError extends Error {
constructor(message, code, detail) {
super(message);
this.name = 'ApiError';
this.code = typeof code === 'number' ? code : 500;
if (detail !== undefined) {
this.detail = detail;
}
}
}
class FileError extends Error {
constructor(message, err) {
super(message);
this.name = 'FileError';
for (let e in err) this[e] = err[e];
}
}
// Export the response object
module.exports = {
RouteError,
MethodError,
ConfigurationError,
ResponseError,
ApiError,
FileError,
};