Skip to content

Commit c3bff8d

Browse files
committed
fix(github): retain GraphQL forbidden error classification
1 parent b085d94 commit c3bff8d

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ it.effect("maps credential verification failures without relabeling operation fa
7070
);
7171

7272
it.effect.each([
73-
{ status: 403, reason: "forbidden" },
74-
{ status: 503, reason: "failed" },
75-
])("classifies GitHub response $status as $reason", ({ status, reason }) =>
73+
{ status: 403, githubErrorTypes: [], reason: "forbidden" },
74+
{ status: 503, githubErrorTypes: [], reason: "failed" },
75+
{ status: 200, githubErrorTypes: ["FORBIDDEN"], reason: "forbidden" },
76+
{ status: 200, githubErrorTypes: ["INTERNAL"], reason: "failed" },
77+
])("classifies GitHub response $status as $reason", ({ status, githubErrorTypes, reason }) =>
7678
Effect.gen(function* () {
7779
const provider = yield* make.pipe(
7880
Effect.provide(
@@ -84,6 +86,7 @@ it.effect.each([
8486
host: "github.com",
8587
operation: "detail",
8688
status,
89+
githubErrorTypes,
8790
}),
8891
),
8992
}),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ function gitHubProviderFailure(
121121
case "SourceControlRateLimitPausedError":
122122
return { reason: "rate-limited", retryAt: error.retryAt };
123123
case "GitHubApiResponseError":
124-
return { reason: error.status === 403 ? "forbidden" : "failed" };
124+
return {
125+
reason:
126+
error.status === 403 || error.githubErrorTypes?.includes("FORBIDDEN")
127+
? "forbidden"
128+
: "failed",
129+
};
125130
case "GitHubApiNotFoundError":
126131
return error.credential === undefined || error.credential === "app"
127132
? { reason: "not-found" }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +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)),
8889
},
8990
) {
9091
override get message(): string {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ describe("call", () => {
311311
_tag: "GitHubApiResponseError",
312312
status: 200,
313313
githubErrors: ["Could not resolve", "Resource not accessible"],
314+
githubErrorTypes: ["NOT_FOUND", "FORBIDDEN"],
314315
});
315316
}).pipe(Effect.provide(layer));
316317
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ 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"]] : [],
253+
),
251254
});
252255
};
253256

0 commit comments

Comments
 (0)