mirror of
https://github.com/actions/stale.git
synced 2025-12-10 03:57:04 +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:
9
dist/index.js
vendored
9
dist/index.js
vendored
@@ -761,6 +761,7 @@ class IssuesProcessor {
|
||||
});
|
||||
}
|
||||
getRateLimit() {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const logger = new logger_1.Logger();
|
||||
try {
|
||||
@@ -768,7 +769,13 @@ class IssuesProcessor {
|
||||
return new rate_limit_1.RateLimit(rateLimitResult.data.rate);
|
||||
}
|
||||
catch (error) {
|
||||
logger.error(`Error when getting rateLimit: ${error.message}`);
|
||||
const status = error === null || error === void 0 ? void 0 : error.status;
|
||||
const message = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 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}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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