Fix mock data structure for rate limit and NOT_FOUND error handling (#399)

* Initial plan

* Fix mock data structure and error handling for rate limit tests

Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>

* Minor cleanup: reorder handleError parameter fields for clarity

Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>

* Address code review feedback: remove unsafe non-null assertion and improve variable naming

Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>

* Fix test mock setup: remove mock calls for commented-out test and add missing mocks for requestUserInfo

Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>

* Clarify comment about retry attempts in test mock setup

Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ryo-ma <6661165+ryo-ma@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-12 11:18:32 +09:00 • committed by GitHub
parent 1183dbf0b7
commit f2b0ae119a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 52 additions and 31 deletions

View file

@ -1,4 +1,5 @@
{
"data": {
"data": {
"user": null
},
@ -18,3 +19,4 @@
}
]
}
}

View file

@ -7,6 +7,9 @@
},
"rate_limit": {
"data": {
"data": {
"user": null
},
"errors": [
{
"type": "RATE_LIMITED",

View file

@ -28,14 +28,26 @@ stub(
new Promise((resolve) => {
resolve(successGithubResponseMock.default);
}),
// // Should get data in second Retry
// Should throw NOT FOUND (requestUserInfo makes 4 API calls: repository, activity, issue, pullRequest)
// Each call makes 2 attempts (one per token), so 8 promises total
new Promise((resolve) => {
resolve(rateLimitMock.default.rate_limit);
resolve(notFoundGithubResponseMock.default);
}),
new Promise((resolve) => {
resolve(successGithubResponseMock.default);
resolve(notFoundGithubResponseMock.default);
}),
new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default);
}),
new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default);
}),
new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default);
}),
new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default);
}),
// Should throw NOT FOUND
new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default);
}),

View file

@ -1,6 +1,7 @@
import { soxa } from "../../deps.ts";
import {
EServiceKindError,
GithubError,
GithubErrorResponse,
GithubExceedError,
QueryDefaultResponse,
@ -24,26 +25,28 @@ export async function requestGithubData<T = unknown>(
return responseData.data.user;
}
throw handleError(
responseData as unknown as GithubErrorResponse | GithubExceedError,
);
throw handleError(responseData);
}
function handleError(
reponseErrors: GithubErrorResponse | GithubExceedError,
responseData: {
data?: unknown;
errors?: GithubError[];
message?: string;
documentation_url?: string;
},
): ServiceError {
let isRateLimitExceeded = false;
const arrayErrors = (reponseErrors as GithubErrorResponse)?.errors || [];
const objectError = (reponseErrors as GithubExceedError) || {};
const arrayErrors = responseData?.errors || [];
if (Array.isArray(arrayErrors)) {
if (Array.isArray(arrayErrors) && arrayErrors.length > 0) {
isRateLimitExceeded = arrayErrors.some((error) =>
error.type.includes(EServiceKindError.RATE_LIMIT)
);
}
if (objectError?.message) {
isRateLimitExceeded = objectError?.message.includes(
if (responseData?.message) {
isRateLimitExceeded = responseData.message.toLowerCase().includes(
"rate limit",
);
}

View file

@ -15,7 +15,8 @@ export type GithubExceedError = {
export type QueryDefaultResponse<T = unknown> = {
data: {
data: T;
errors?: GithubErrorResponse;
errors?: GithubError[];
message?: string;
documentation_url?: string;
};
};