mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
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:
parent
1183dbf0b7
commit
f2b0ae119a
5 changed files with 52 additions and 31 deletions
|
|
@ -1,20 +1,22 @@
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"user": null
|
"data": {
|
||||||
},
|
"user": null
|
||||||
"errors": [
|
},
|
||||||
{
|
"errors": [
|
||||||
"type": "NOT_FOUND",
|
{
|
||||||
"path": [
|
"type": "NOT_FOUND",
|
||||||
"user"
|
"path": [
|
||||||
],
|
"user"
|
||||||
"locations": [
|
],
|
||||||
{
|
"locations": [
|
||||||
"line": 2,
|
{
|
||||||
"column": 5
|
"line": 2,
|
||||||
}
|
"column": 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'."
|
||||||
]
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
},
|
},
|
||||||
"rate_limit": {
|
"rate_limit": {
|
||||||
"data": {
|
"data": {
|
||||||
|
"data": {
|
||||||
|
"user": null
|
||||||
|
},
|
||||||
"errors": [
|
"errors": [
|
||||||
{
|
{
|
||||||
"type": "RATE_LIMITED",
|
"type": "RATE_LIMITED",
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue