Skip to content

Commit

Permalink
chore: handle 5xx errors with special message as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebrynes7 committed Jan 3, 2025
1 parent 82dca5b commit 65cbed6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
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

0 comments on commit 65cbed6

Please sign in to comment.