-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement error module * add errors classes to distinguish error instances
- Loading branch information
1 parent
29e58ac
commit 377f861
Showing
17 changed files
with
123 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function createErrorFactory(errorName: string) { | ||
return class CustomError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = errorName; // Set the error name provided to the factory | ||
Error.captureStackTrace(this, CustomError); // Capture the stack trace and omit the constructor frame | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ApiError } from "../error.js"; | ||
|
||
export class BeaconchainApiError extends ApiError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "BeaconchainApiError"; // Override the name if needed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ApiError } from "../error.js"; | ||
|
||
export class BlockExplorerApiError extends ApiError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "BlockExplorerApiError"; // Override the name if needed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,3 @@ | ||
import type { ErrorCode, ErrnoException } from "./types.js"; | ||
import { createErrorFactory } from "../../createErrorFactory.js"; | ||
|
||
export class ApiError extends Error { | ||
public code: ErrorCode; | ||
public errno: number; | ||
public path?: string; | ||
public syscall?: string; | ||
public hostname?: string; | ||
public address?: string; | ||
public port?: number; | ||
|
||
constructor(error: ErrnoException) { | ||
super(error.message); | ||
this.code = error.code || "UNKNOWN"; | ||
this.errno = error.errno || -1; | ||
this.path = error.path; | ||
this.syscall = error.syscall; | ||
this.hostname = error.hostname; | ||
this.address = error.address; | ||
this.port = error.port; | ||
} | ||
} | ||
export const ApiError = createErrorFactory("ApiError"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ApiError } from "../error.js"; | ||
|
||
export class PostgresApiError extends ApiError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "PostgresApiError"; // Override the name if needed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ApiError } from "../error.js"; | ||
|
||
export class SignerApiError extends ApiError { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "SignerApiError"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.