File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,43 @@ export abstract class CustomError extends Error {
46
46
}
47
47
}
48
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
+
60
+ this . code = extras . code ;
61
+ this . statusCode = extras . statusCode ;
62
+ this . cause = extras . cause ;
63
+ }
64
+
65
+ public readonly code ?: string ;
66
+ public readonly statusCode ?: number ;
67
+ public readonly cause ?: Error ;
68
+ }
69
+
70
+ export class StatusError extends ErrorWithExtras {
71
+ constructor (
72
+ /**
73
+ * Should be a valid HTTP status code
74
+ */
75
+ statusCode : number ,
76
+ message : string ,
77
+ extras : {
78
+ code ?: string ,
79
+ cause ?: Error
80
+ } = { }
81
+ ) {
82
+ super ( message , { ...extras , statusCode : statusCode } ) ;
83
+ }
84
+ }
85
+
49
86
/**
50
87
* An error to throw in expected-never cases - by using this, you ask TypeScript to
51
88
* be sure that it agrees that the case is truly unreachable.
You can’t perform that action at this time.
0 commit comments