Skip to content

Commit 90332de

Browse files
committed
Move extras option into CustomError itself
1 parent a2e14e7 commit 90332de

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/errors.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,19 @@ export function asErrorLike(error: any): ErrorLike {
3535
}
3636
}
3737

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.
3940
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+
} = {}) {
4146
super(message); // 'Error' breaks prototype chain here
4247

4348
// This restores the details of the real error subclass:
4449
this.name = new.target.name;
4550
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);
5951

6052
this.code = extras.code;
6153
this.statusCode = extras.statusCode;
@@ -67,7 +59,7 @@ export class ErrorWithExtras extends CustomError {
6759
public readonly cause?: Error;
6860
}
6961

70-
export class StatusError extends ErrorWithExtras {
62+
export class StatusError extends CustomError {
7163
constructor(
7264
/**
7365
* Should be a valid HTTP status code

0 commit comments

Comments
 (0)