-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy patherrors.ts
More file actions
45 lines (35 loc) · 1022 Bytes
/
errors.ts
File metadata and controls
45 lines (35 loc) · 1022 Bytes
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
import { AxiosError } from 'axios';
import type { GitifyError } from '../../types';
import type { GitHubRESTError } from '../../typesGitHub';
import { Errors } from '../errors';
export function determineFailureType(
err: AxiosError<GitHubRESTError>,
): GitifyError {
const code = err.code;
if (code === AxiosError.ERR_NETWORK) {
return Errors.NETWORK;
}
if (err.message?.includes('safeStorage')) {
return Errors.BAD_CREDENTIALS;
}
if (code !== AxiosError.ERR_BAD_REQUEST) {
return Errors.UNKNOWN;
}
const status = err.response.status;
const message = err.response.data.message;
if (status === 401) {
return Errors.BAD_CREDENTIALS;
}
if (status === 403) {
if (message.includes("Missing the 'notifications' scope")) {
return Errors.MISSING_SCOPES;
}
if (
message.includes('API rate limit exceeded') ||
message.includes('You have exceeded a secondary rate limit')
) {
return Errors.RATE_LIMITED;
}
}
return Errors.UNKNOWN;
}