-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherrors.ts
105 lines (85 loc) · 2.56 KB
/
errors.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* OAuth2AuthCodePKCE errors
*/
export class ErrorOAuth2 {
}
/**
* Some generic, internal errors
*/
// for really unknown errors
export class ErrorUnknown extends ErrorOAuth2 {
constructor(readonly message: string) {
super();
}
}
export class ErrorNoAccessToken extends ErrorOAuth2 {
}
export class ErrorNoAuthCode extends ErrorOAuth2 {
}
export class ErrorInvalidReturnedStateParam extends ErrorOAuth2 {
}
/**
* Errors that occur across many endpoints
*/
export class ErrorInvalidScope extends ErrorOAuth2 {
}
export class ErrorInvalidRequest extends ErrorOAuth2 {
}
export class ErrorInvalidToken extends ErrorOAuth2 {
}
/**
* Authorization grant errors thrown by the redirection from the
* authorization server
*/
export class ErrorAuthenticationGrant extends ErrorOAuth2 {
}
export class ErrorUnauthorizedClient extends ErrorAuthenticationGrant {
}
export class ErrorAccessDenied extends ErrorAuthenticationGrant {
}
export class ErrorUnsupportedResponseType extends ErrorAuthenticationGrant {
}
export class ErrorServerError extends ErrorAuthenticationGrant {
}
export class ErrorTemporarilyUnavailable extends ErrorAuthenticationGrant {
}
/**
* Access token response errors
*/
export class ErrorAccessTokenResponse extends ErrorOAuth2 {
}
export class ErrorInvalidClient extends ErrorAccessTokenResponse {
}
export class ErrorInvalidGrant extends ErrorAccessTokenResponse {
}
export class ErrorUnsupportedGrantType extends ErrorAccessTokenResponse {
}
export const RAW_ERROR_TO_ERROR_CLASS_MAP: {[error_name: string]: typeof ErrorOAuth2} = {
invalid_request: ErrorInvalidRequest,
invalid_grant: ErrorInvalidGrant,
unauthorized_client: ErrorUnauthorizedClient,
access_denied: ErrorAccessDenied,
unsupported_response_type: ErrorUnsupportedResponseType,
invalid_scope: ErrorInvalidScope,
server_error: ErrorServerError,
temporarily_unavailable: ErrorTemporarilyUnavailable,
invalid_client: ErrorInvalidClient,
unsupported_grant_type: ErrorUnsupportedGrantType,
invalid_token: ErrorInvalidToken,
};
/**
* Convert an error string returned from the server to an error object.
*/
export const toErrorObject = (rawError: string): ErrorOAuth2 => {
const errorClass = RAW_ERROR_TO_ERROR_CLASS_MAP[rawError];
return errorClass ? new errorClass() : new ErrorUnknown(rawError);
};
/**
* WWW-Authenticate error object structure
*/
export class ErrorWWWAuthenticate {
public realm: string = '';
public error: string = '';
public errorDescription: string | undefined;
public errorUri: string | undefined;
}