From 19a18a08c507163b3bbcbd1f535143bf4739d7a3 Mon Sep 17 00:00:00 2001 From: Nuno Sousa Date: Fri, 18 Oct 2024 11:47:42 +0100 Subject: [PATCH] fix: warning if rate limit is disabled --- dist/index.js | 24 ++++++++++++++++++++++-- src/classes/issues-processor.ts | 27 ++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6fe079ac0..699eefa68 100644 --- a/dist/index.js +++ b/dist/index.js @@ -744,10 +744,30 @@ class IssuesProcessor { const logger = new logger_1.Logger(); try { const rateLimitResult = yield this.client.rest.rateLimit.get(); - return new rate_limit_1.RateLimit(rateLimitResult.data.rate); + if (rateLimitResult.data.rate) { + return new rate_limit_1.RateLimit(rateLimitResult.data.rate); + } + else { + logger.warning('Rate limit is disabled or not available.'); + return null; + } } catch (error) { - logger.error(`Error when getting rateLimit: ${error.message}`); + if (error instanceof Error) { + if (error.message.includes('Not Found') || + error.message.includes('404')) { + logger.warning('Rate limit endpoint not found. Rate limiting may be disabled.'); + return null; + } + else { + logger.error(`Error when getting rateLimit: ${error.message}`); + throw error; + } + } + else { + logger.error('An unknown error occurred when getting rateLimit'); + throw error; + } } }); } diff --git a/src/classes/issues-processor.ts b/src/classes/issues-processor.ts index 486c6a78a..b6bc5aa7d 100644 --- a/src/classes/issues-processor.ts +++ b/src/classes/issues-processor.ts @@ -639,13 +639,34 @@ export class IssuesProcessor { } } - async getRateLimit(): Promise { + async getRateLimit(): Promise { const logger: Logger = new Logger(); try { const rateLimitResult = await this.client.rest.rateLimit.get(); - return new RateLimit(rateLimitResult.data.rate); + if (rateLimitResult.data.rate) { + return new RateLimit(rateLimitResult.data.rate); + } else { + logger.warning('Rate limit is disabled or not available.'); + return null; + } } catch (error) { - logger.error(`Error when getting rateLimit: ${error.message}`); + if (error instanceof Error) { + if ( + error.message.includes('Not Found') || + error.message.includes('404') + ) { + logger.warning( + 'Rate limit endpoint not found. Rate limiting may be disabled.' + ); + return null; + } else { + logger.error(`Error when getting rateLimit: ${error.message}`); + throw error; + } + } else { + logger.error('An unknown error occurred when getting rateLimit'); + throw error; + } } }