Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: warning if rate limit is disabled #1185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
}
Expand Down
27 changes: 24 additions & 3 deletions src/classes/issues-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,34 @@ export class IssuesProcessor {
}
}

async getRateLimit(): Promise<IRateLimit | undefined> {
async getRateLimit(): Promise<IRateLimit | null> {
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;
}
}
}

Expand Down