Skip to content

Commit fad0de8

Browse files
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.
1 parent 39bea7d commit fad0de8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

dist/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,21 @@ class IssuesProcessor {
761761
});
762762
}
763763
getRateLimit() {
764+
var _a;
764765
return __awaiter(this, void 0, void 0, function* () {
765766
const logger = new logger_1.Logger();
766767
try {
767768
const rateLimitResult = yield this.client.rest.rateLimit.get();
768769
return new rate_limit_1.RateLimit(rateLimitResult.data.rate);
769770
}
770771
catch (error) {
771-
logger.error(`Error when getting rateLimit: ${error.message}`);
772+
const status = error === null || error === void 0 ? void 0 : error.status;
773+
const message = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : String(error);
774+
if (status === 404 && message.includes('Rate limiting is not enabled')) {
775+
logger.warning('Rate limiting is not enabled on this instance. Proceeding without rate limit checks.');
776+
return undefined;
777+
}
778+
logger.error(`Error when getting rateLimit: ${message}`);
772779
}
773780
});
774781
}

src/classes/issues-processor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,22 @@ export class IssuesProcessor {
660660

661661
async getRateLimit(): Promise<IRateLimit | undefined> {
662662
const logger: Logger = new Logger();
663+
663664
try {
664665
const rateLimitResult = await this.client.rest.rateLimit.get();
665666
return new RateLimit(rateLimitResult.data.rate);
666-
} catch (error) {
667-
logger.error(`Error when getting rateLimit: ${error.message}`);
667+
} catch (error: unknown) {
668+
const status = (error as {status?: number})?.status;
669+
const message = (error as {message?: string})?.message ?? String(error);
670+
671+
if (status === 404 && message.includes('Rate limiting is not enabled')) {
672+
logger.warning(
673+
'Rate limiting is not enabled on this instance. Proceeding without rate limit checks.'
674+
);
675+
return undefined;
676+
}
677+
678+
logger.error(`Error when getting rateLimit: ${message}`);
668679
}
669680
}
670681

0 commit comments

Comments
 (0)