-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d772d61
commit b386fe4
Showing
2 changed files
with
97 additions
and
4 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
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,39 @@ | ||
import { PythonException } from "python-bridge"; | ||
|
||
export abstract class CustomException { | ||
constructor( | ||
public name: string, | ||
public error?: Error | unknown, | ||
) {} | ||
|
||
abstract getMessage(): string; | ||
} | ||
|
||
export class CustomPythonException extends CustomException { | ||
constructor( | ||
public name: string, | ||
public error: PythonException, | ||
) { | ||
super(name, error); | ||
} | ||
|
||
getMessage(): string { | ||
return this.error.exception.message; | ||
} | ||
} | ||
|
||
export class CustomUnknownException extends CustomException { | ||
constructor( | ||
public name: string, | ||
public error: unknown, | ||
) { | ||
super(name, error); | ||
} | ||
|
||
getMessage(): string { | ||
if (this.error && this.error instanceof Error) { | ||
return this.error.message; | ||
} | ||
return `${this.error}`; | ||
} | ||
} |