fix(connect): refresh relay credentials before expiry (#9178)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
a19f01fc19
commit
9e646ad84c
8 files changed
+153
-9
No files matched your search
@@ -1,8 +1,13 @@
|
||||
import type { PullRequestDiffInput, PullRequestDiffResult } from "@t3tools/contracts";
|
||||
import {
|
||||
EnvironmentAuthInvalidError,
|
||||
type PullRequestDiffInput,
|
||||
type PullRequestDiffResult,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
|
||||
import type { PreparedConnection } from "../connection/model.ts";
|
||||
@@ -17,6 +22,24 @@ import { buildEnvironmentAuthHeaders, withEnvironmentCredentials } from "./envir
|
||||
|
||||
const DEFAULT_PULL_REQUEST_DIFF_TIMEOUT_MS = 60_000;
|
||||
|
||||
export class PullRequestDiffCredentialRejectedError extends Schema.TaggedErrorClass<PullRequestDiffCredentialRejectedError>()(
|
||||
"PullRequestDiffCredentialRejectedError",
|
||||
{
|
||||
repository: Schema.String,
|
||||
number: Schema.Number,
|
||||
traceId: Schema.String,
|
||||
cause: EnvironmentAuthInvalidError,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return "This environment session is no longer valid (invalid_credential). Refresh the page or quit and reopen T3 Code.";
|
||||
}
|
||||
}
|
||||
|
||||
export type PullRequestDiffLoadError =
|
||||
| RemoteEnvironmentRequestError
|
||||
| PullRequestDiffCredentialRejectedError;
|
||||
|
||||
export const fetchEnvironmentPullRequestDiff = Effect.fn(
|
||||
"clientRuntime.state.fetchEnvironmentPullRequestDiff",
|
||||
)(function* (input: {
|
||||
@@ -42,6 +65,17 @@ export const fetchEnvironmentPullRequestDiff = Effect.fn(
|
||||
input.prepared.httpAuthorization,
|
||||
client.pullRequests.diff({ payload: input.diff, headers }),
|
||||
),
|
||||
).pipe(
|
||||
Effect.mapError((error) =>
|
||||
error._tag === "EnvironmentAuthInvalidError" && error.reason === "invalid_credential"
|
||||
? new PullRequestDiffCredentialRejectedError({
|
||||
repository: input.diff.repository,
|
||||
number: input.diff.number,
|
||||
traceId: error.traceId,
|
||||
cause: error,
|
||||
})
|
||||
: error,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -51,7 +85,7 @@ export class PullRequestDiffLoader extends Context.Service<
|
||||
readonly load: (
|
||||
prepared: PreparedConnection,
|
||||
input: PullRequestDiffInput,
|
||||
) => Effect.Effect<PullRequestDiffResult, RemoteEnvironmentRequestError>;
|
||||
) => Effect.Effect<PullRequestDiffResult, PullRequestDiffLoadError>;
|
||||
}
|
||||
>()("@t3tools/client-runtime/state/pullRequestDiffHttp/PullRequestDiffLoader") {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user