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(platform): handle unexpected github-graphql error #22512

Merged
merged 5 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions lib/constants/error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const PLATFORM_GPG_FAILED = 'gpg-failed';
export const PLATFORM_INTEGRATION_UNAUTHORIZED = 'integration-unauthorized';
export const PLATFORM_NOT_FOUND = 'platform-not-found';
export const PLATFORM_RATE_LIMIT_EXCEEDED = 'rate-limit-exceeded';
export const PLATFORM_UNKOWN_ERROR = 'rate-limit-exceeded';
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

// Config Error
export const CONFIG_VALIDATION = 'config-validation';
Expand Down
18 changes: 18 additions & 0 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as httpMock from '../../../../test/http-mock';
import { logger, mocked, partial } from '../../../../test/util';
import { GlobalConfig } from '../../../config/global';
import {
PLATFORM_UNKOWN_ERROR,
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
REPOSITORY_CANNOT_FORK,
REPOSITORY_NOT_FOUND,
REPOSITORY_RENAMED,
Expand Down Expand Up @@ -542,6 +543,23 @@ describe('modules/platform/github/index', () => {
).rejects.toThrow(REPOSITORY_NOT_FOUND);
});

it('throws unexpected graphql errors', async () => {
httpMock
.scope(githubApiHost)
.post(`/graphql`)
.reply(200, {
errors: [
{
type: 'RATE_LIMITED',
message: 'API rate limit exceeded for installation ID XXXXXXX.',
},
],
});
await expect(
github.initRepo({ repository: 'some/repo' })
).rejects.toThrow(PLATFORM_UNKOWN_ERROR);
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
});

it('should throw error if renamed', async () => {
httpMock
.scope(githubApiHost)
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import semver from 'semver';
import { GlobalConfig } from '../../../config/global';
import {
PLATFORM_INTEGRATION_UNAUTHORIZED,
PLATFORM_UNKOWN_ERROR,
REPOSITORY_ACCESS_FORBIDDEN,
REPOSITORY_ARCHIVED,
REPOSITORY_BLOCKED,
Expand Down Expand Up @@ -394,6 +395,12 @@ export async function initRepo({
name: config.repositoryName,
},
});

if (res?.errors) {
logger.debug({ res }, 'Unexpected Graph QL errors');
throw new Error(PLATFORM_UNKOWN_ERROR);
}
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved

repo = res?.data?.repository;
// istanbul ignore if
if (!repo) {
Expand Down