๐Ÿ“ฆ ionic-team / capacitor

๐Ÿ“„ errors.ts ยท 26 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26export abstract class BaseException<T> extends Error {
  constructor(
    readonly message: string,
    readonly code: T,
  ) {
    super(message);
  }
}

export class FatalException extends BaseException<'FATAL'> {
  constructor(
    readonly message: string,
    readonly exitCode = 1,
  ) {
    super(message, 'FATAL');
  }
}

export function fatal(message: string): never {
  throw new FatalException(message);
}

export function isFatal(e: any): e is FatalException {
  return e && e instanceof FatalException;
}