mirror of
https://github.com/actions/stale.git
synced 2026-02-07 06:38:18 +00:00
Improves error handling when rate limiting is disabled on GHES. (#1300)
* rateLimitResult log * code update for rate limit * Refactor getRateLimit method to remove mock responses and improve error handling * retry logic removed * Simplify warning message for rate limiting not enabled * Remove redundant comments in rate limiting error handling * updated the block to use catch (error: unknown) instead of any and added simple type narrowing for status and message.
This commit is contained in:
@@ -660,11 +660,22 @@ export class IssuesProcessor {
|
||||
|
||||
async getRateLimit(): Promise<IRateLimit | undefined> {
|
||||
const logger: Logger = new Logger();
|
||||
|
||||
try {
|
||||
const rateLimitResult = await this.client.rest.rateLimit.get();
|
||||
return new RateLimit(rateLimitResult.data.rate);
|
||||
} catch (error) {
|
||||
logger.error(`Error when getting rateLimit: ${error.message}`);
|
||||
} catch (error: unknown) {
|
||||
const status = (error as {status?: number})?.status;
|
||||
const message = (error as {message?: string})?.message ?? String(error);
|
||||
|
||||
if (status === 404 && message.includes('Rate limiting is not enabled')) {
|
||||
logger.warning(
|
||||
'Rate limiting is not enabled on this instance. Proceeding without rate limit checks.'
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
logger.error(`Error when getting rateLimit: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user