File tree Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Original file line number Diff line number Diff line change @@ -35,27 +35,19 @@ export function asErrorLike(error: any): ErrorLike {
35
35
}
36
36
}
37
37
38
- // Tiny wrapper to make it super easy to make custom error classes where .name behaves correctly.
38
+ // Tiny wrapper to make it super easy to make custom error classes where .name behaves
39
+ // correctly, and useful metafields can be easily added.
39
40
export abstract class CustomError extends Error {
40
- constructor ( message ?: string ) {
41
+ constructor ( message ?: string , extras : {
42
+ code ?: string ,
43
+ statusCode ?: number ,
44
+ cause ?: Error
45
+ } = { } ) {
41
46
super ( message ) ; // 'Error' breaks prototype chain here
42
47
43
48
// This restores the details of the real error subclass:
44
49
this . name = new . target . name ;
45
50
Object . setPrototypeOf ( this , new . target . prototype ) ;
46
- }
47
- }
48
-
49
- export class ErrorWithExtras extends CustomError {
50
- constructor (
51
- message : string ,
52
- extras : {
53
- code ?: string ,
54
- statusCode ?: number ,
55
- cause ?: Error
56
- }
57
- ) {
58
- super ( message ) ;
59
51
60
52
this . code = extras . code ;
61
53
this . statusCode = extras . statusCode ;
@@ -67,7 +59,7 @@ export class ErrorWithExtras extends CustomError {
67
59
public readonly cause ?: Error ;
68
60
}
69
61
70
- export class StatusError extends ErrorWithExtras {
62
+ export class StatusError extends CustomError {
71
63
constructor (
72
64
/**
73
65
* Should be a valid HTTP status code
You can’t perform that action at this time.
0 commit comments