Skip to content

Commit 793be57

Browse files
committed
fix(github): keep mixed GraphQL read failures retryable
1 parent c3bff8d commit 793be57

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎packages/source-control-github/src/server/GitHubPullRequestProvider.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ it.effect.each([
7474
{ status: 503, githubErrorTypes: [], reason: "failed" },
7575
{ status: 200, githubErrorTypes: ["FORBIDDEN"], reason: "forbidden" },
7676
{ status: 200, githubErrorTypes: ["INTERNAL"], reason: "failed" },
77+
{ status: 200, githubErrorTypes: ["FORBIDDEN", "NOT_FOUND"], reason: "forbidden" },
78+
{ status: 200, githubErrorTypes: ["FORBIDDEN", "INTERNAL"], reason: "failed" },
79+
{ status: 200, githubErrorTypes: ["FORBIDDEN", null], reason: "failed" },
7780
])("classifies GitHub response $status as $reason", ({ status, githubErrorTypes, reason }) =>
7881
Effect.gen(function* () {
7982
const provider = yield* make.pipe(

‎packages/source-control-github/src/server/GitHubPullRequestProvider.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ function gitHubProviderFailure(
123123
case "GitHubApiResponseError":
124124
return {
125125
reason:
126-
error.status === 403 || error.githubErrorTypes?.includes("FORBIDDEN")
126+
error.status === 403 ||
127+
(error.githubErrorTypes?.includes("FORBIDDEN") &&
128+
error.githubErrorTypes.every((type) => type === "FORBIDDEN" || type === "NOT_FOUND"))
127129
? "forbidden"
128130
: "failed",
129131
};

‎packages/source-control-github/src/server/GitHubRequestPolicy.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class GitHubApiResponseError extends Schema.TaggedError<GitHubApiResponse
8585
operation: Schema.String,
8686
status: Schema.Int,
8787
githubErrors: Schema.optionalKey(Schema.Array(Schema.String)),
88-
githubErrorTypes: Schema.optionalKey(Schema.Array(Schema.String)),
88+
githubErrorTypes: Schema.optionalKey(Schema.Array(Schema.NullOr(Schema.String))),
8989
},
9090
) {
9191
override get message(): string {

‎packages/source-control-github/src/server/gitHubGraphQlClient.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ describe("call", () => {
302302
errors: [
303303
{ type: "NOT_FOUND", message: "Could not resolve" },
304304
{ type: "FORBIDDEN", message: "Resource not accessible" },
305+
{ message: "Unknown error" },
305306
],
306307
}),
307308
);
@@ -310,8 +311,8 @@ describe("call", () => {
310311
expect(error).toMatchObject({
311312
_tag: "GitHubApiResponseError",
312313
status: 200,
313-
githubErrors: ["Could not resolve", "Resource not accessible"],
314-
githubErrorTypes: ["NOT_FOUND", "FORBIDDEN"],
314+
githubErrors: ["Could not resolve", "Resource not accessible", "Unknown error"],
315+
githubErrorTypes: ["NOT_FOUND", "FORBIDDEN", null],
315316
});
316317
}).pipe(Effect.provide(layer));
317318
},

‎packages/source-control-github/src/server/gitHubGraphQlClient.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ const fromClientError = (
248248
...context,
249249
status: reason.status ?? 200,
250250
githubErrors: reason.errors.map((graphQlError) => graphQlError.message),
251-
githubErrorTypes: reason.errors.flatMap((graphQlError) =>
252-
typeof graphQlError["type"] === "string" ? [graphQlError["type"]] : [],
251+
githubErrorTypes: reason.errors.map((graphQlError) =>
252+
typeof graphQlError["type"] === "string" ? graphQlError["type"] : null,
253253
),
254254
});
255255
};

0 commit comments

Comments
 (0)