|
1 | | -export interface TransitionAbortedErrorContructor { |
2 | | - new (message?: string): ITransitionAbortedError; |
3 | | - readonly prototype: ITransitionAbortedError; |
| 1 | +export interface TransitionAbortedError extends Error { |
| 2 | + name: 'TransitionAborted'; |
| 3 | + code: 'TRANSITION_ABORTED'; |
4 | 4 | } |
5 | 5 |
|
6 | | -export interface ITransitionAbortedError extends Error { |
7 | | - constructor: TransitionAbortedErrorContructor; |
| 6 | +export function isTransitionAborted(maybeError: unknown): maybeError is TransitionAbortedError { |
| 7 | + return ( |
| 8 | + typeof maybeError === 'object' && |
| 9 | + maybeError !== null && |
| 10 | + (maybeError as TransitionAbortedError).code === 'TRANSITION_ABORTED' |
| 11 | + ); |
8 | 12 | } |
9 | 13 |
|
10 | | -const TransitionAbortedError: TransitionAbortedErrorContructor = (function () { |
11 | | - TransitionAbortedError.prototype = Object.create(Error.prototype); |
12 | | - TransitionAbortedError.prototype.constructor = TransitionAbortedError; |
| 14 | +export function buildTransitionAborted(): TransitionAbortedError { |
| 15 | + let error = new Error('TransitionAborted') as TransitionAbortedError; |
| 16 | + error.name = 'TransitionAborted'; |
| 17 | + error.code = 'TRANSITION_ABORTED'; |
13 | 18 |
|
14 | | - function TransitionAbortedError(this: ITransitionAbortedError, message?: string) { |
15 | | - let error = Error.call(this, message); |
16 | | - this.name = 'TransitionAborted'; |
17 | | - this.message = message || 'TransitionAborted'; |
18 | | - |
19 | | - if (Error.captureStackTrace) { |
20 | | - Error.captureStackTrace(this, TransitionAbortedError); |
21 | | - } else { |
22 | | - this.stack = error.stack; |
23 | | - } |
24 | | - } |
25 | | - |
26 | | - return TransitionAbortedError as any; |
27 | | -})(); |
28 | | - |
29 | | -export default TransitionAbortedError; |
| 19 | + return error; |
| 20 | +} |
0 commit comments