Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: handle 5xx errors with special message as well #384

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions plugin/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export enum QueryErrorKind {
BadRequest = 0,
Unauthorized = 1,
Forbidden = 2,
Unknown = 3,
ServerError = 3,
Unknown = 4,
}

export type SubscriptionResult =
Expand Down Expand Up @@ -225,16 +226,14 @@ class Subscription {
kind: QueryErrorKind.Unknown,
};
if (error instanceof TodoistApiError) {
switch (error.statusCode) {
case 400:
result.kind = QueryErrorKind.BadRequest;
break;
case 401:
result.kind = QueryErrorKind.Unauthorized;
break;
case 403:
result.kind = QueryErrorKind.Forbidden;
break;
if (error.statusCode === 400) {
result.kind = QueryErrorKind.BadRequest;
} else if (error.statusCode === 401) {
result.kind = QueryErrorKind.Unauthorized;
} else if (error.statusCode === 403) {
result.kind = QueryErrorKind.Forbidden;
} else if (error.statusCode > 500) {
result.kind = QueryErrorKind.ServerError;
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/src/i18n/langs/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export const en: Translations = {
"The Todoist API has rejected the request. Please check the filter to ensure it is valid.",
unauthorized:
"The Todoist API request is missing or has the incorrect credentials. Please check the API token in the settings.",
serverError:
"The Todoist API has returned an error. Please check Todoist's status page: https://status.todoist.net/ and try again later.",
unknown:
"Unknown error occurred. Please check the Console in the Developer Tools window for more information",
},
Expand Down
1 change: 1 addition & 0 deletions plugin/src/i18n/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export type Translations = {
header: string;
badRequest: string;
unauthorized: string;
serverError: string;
unknown: string;
};
parsingError: {
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/ui/query/displays/ErrorDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const getErrorMessage = (
case QueryErrorKind.BadRequest:
return i18n.badRequest;
case QueryErrorKind.Unauthorized:
case QueryErrorKind.Forbidden:
return i18n.unauthorized;
case QueryErrorKind.ServerError:
return i18n.serverError;
default:
return i18n.unknown;
}
Expand Down
Loading