From 1afb406f1f84d211905562fde9975af09e5068d0 Mon Sep 17 00:00:00 2001 From: Alex Oliveira Date: Sat, 30 Sep 2023 09:56:01 +0100 Subject: [PATCH] fix: check of rate limit --- .gitignore | 1 + src/Services/GithubApiService.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2aa5d60a..91b922d4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .env .idea .lock +*.sh diff --git a/src/Services/GithubApiService.ts b/src/Services/GithubApiService.ts index 685bac58..96627c1a 100644 --- a/src/Services/GithubApiService.ts +++ b/src/Services/GithubApiService.ts @@ -91,9 +91,11 @@ export class GithubApiService extends GithubRepository { private handleError(responseErrors: GithubError[]): ServiceError { const errors = responseErrors ?? []; - const isRateLimitExceeded = (errors ?? []).some((error) => { - error.type.includes(EServiceKindError.RATE_LIMIT); - }); + + const isRateLimitExceeded = errors.some((error) => + error.type.includes(EServiceKindError.RATE_LIMIT) || + error.message.includes("rate limit") + ); if (isRateLimitExceeded) { throw new ServiceError( @@ -133,6 +135,10 @@ export class GithubApiService extends GithubRepository { return response?.data?.data?.user ?? new ServiceError("not found", EServiceKindError.NOT_FOUND); } catch (error) { + if (error instanceof ServiceError) { + Logger.error(error); + return error; + } // TODO: Move this to a logger instance later if (error instanceof Error && error.cause) { Logger.error(JSON.stringify(error.cause, null, 2));