1 |
|
2 |
|
3 |
|
4 | export class GenericError extends Error {
|
5 | constructor(public error: string, public error_description: string) {
|
6 | super(error_description);
|
7 | Object.setPrototypeOf(this, GenericError.prototype);
|
8 | }
|
9 |
|
10 | static fromPayload({
|
11 | error,
|
12 | error_description
|
13 | }: {
|
14 | error: string;
|
15 | error_description: string;
|
16 | }) {
|
17 | return new GenericError(error, error_description);
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export class AuthenticationError extends GenericError {
|
26 | constructor(
|
27 | error: string,
|
28 | error_description: string,
|
29 | public state: string,
|
30 | public appState: any = null
|
31 | ) {
|
32 | super(error, error_description);
|
33 |
|
34 | Object.setPrototypeOf(this, AuthenticationError.prototype);
|
35 | }
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export class TimeoutError extends GenericError {
|
43 | constructor() {
|
44 | super('timeout', 'Timeout');
|
45 |
|
46 | Object.setPrototypeOf(this, TimeoutError.prototype);
|
47 | }
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export class PopupTimeoutError extends TimeoutError {
|
54 | constructor(public popup: Window) {
|
55 | super();
|
56 |
|
57 | Object.setPrototypeOf(this, PopupTimeoutError.prototype);
|
58 | }
|
59 | }
|
60 |
|
61 | export class PopupCancelledError extends GenericError {
|
62 | constructor(public popup: Window) {
|
63 | super('cancelled', 'Popup closed');
|
64 |
|
65 | Object.setPrototypeOf(this, PopupCancelledError.prototype);
|
66 | }
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export class MfaRequiredError extends GenericError {
|
73 | constructor(
|
74 | error: string,
|
75 | error_description: string,
|
76 | public mfa_token: string
|
77 | ) {
|
78 | super(error, error_description);
|
79 |
|
80 | Object.setPrototypeOf(this, MfaRequiredError.prototype);
|
81 | }
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export class MissingRefreshTokenError extends GenericError {
|
88 | constructor(public audience: string, public scope: string) {
|
89 | super(
|
90 | 'missing_refresh_token',
|
91 | `Missing Refresh Token (audience: '${valueOrEmptyString(audience, [
|
92 | 'default'
|
93 | ])}', scope: '${valueOrEmptyString(scope)}')`
|
94 | );
|
95 | Object.setPrototypeOf(this, MissingRefreshTokenError.prototype);
|
96 | }
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | function valueOrEmptyString(value: string, exclude: string[] = []) {
|
106 | return value && !exclude.includes(value) ? value : '';
|
107 | }
|