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": { "data": {
"user": null "user": null
}, },
@ -17,4 +18,5 @@
"message": "Could not resolve to a User with the login of 'alekinho'." "message": "Could not resolve to a User with the login of 'alekinho'."
} }
] ]
}
} }

View file

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

View file

@ -28,14 +28,26 @@ stub(
new Promise((resolve) => { new Promise((resolve) => {
resolve(successGithubResponseMock.default); 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) => { new Promise((resolve) => {
resolve(rateLimitMock.default.rate_limit); resolve(notFoundGithubResponseMock.default);
}), }),
new Promise((resolve) => { 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) => { new Promise((resolve) => {
resolve(notFoundGithubResponseMock.default); resolve(notFoundGithubResponseMock.default);
}), }),

View file

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

View file

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