-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappError.js
More file actions
32 lines (26 loc) · 767 Bytes
/
Copy pathappError.js
File metadata and controls
32 lines (26 loc) · 767 Bytes
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
'use strict';
module.exports = class AppError extends Error {
constructor (errno, error, stack = null) {
// Create base Error
super(error);
// Capturing stack trace
if (stack === null) {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = stack;
}
this.errno = errno || 500;
this.error = error || "Unexepected error";
}
static fromError(err) {
// Get sure that err is an Error
if (!(err instanceof Error)) {
throw new AppError(500, "Impossible to create error from a non Error object: (" + err.constructor.name + ") " + err.toString());
}
if (err instanceof AppError) {
return err;
} else {
return new AppError(500, err.message, err.stack);
}
}
};