Skip to content

Commit 9614dc8

Browse files
committed
fix: catch ServerAuthInternalError in getSessionState to preserve graceful degradation
Previously getSessionState only caught ServerAuthInvalidCredentialError, allowing ServerAuthInternalError (e.g. transient database failures) to propagate as unhandled errors. This was a behavior regression from the old implementation which guaranteed getSessionState never failed. Now both error types are caught and gracefully degrade to an unauthenticated state, restoring the original never-fail contract.
1 parent 295145c commit 9614dc8

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

apps/server/src/auth/EnvironmentAuth.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface EnvironmentAuthShape {
9191
readonly getDescriptor: () => Effect.Effect<ServerAuthDescriptor>;
9292
readonly getSessionState: (
9393
request: HttpServerRequest.HttpServerRequest,
94-
) => Effect.Effect<AuthSessionState, ServerAuthInternalError>;
94+
) => Effect.Effect<AuthSessionState>;
9595
readonly createBrowserSession: (
9696
credential: string,
9797
requestMetadata: AuthClientMetadata,
@@ -296,12 +296,18 @@ export const make = Effect.fn("makeEnvironmentAuth")(function* () {
296296
...(session.expiresAt ? { expiresAt: DateTime.toUtc(session.expiresAt) } : {}),
297297
}) satisfies AuthSessionState,
298298
),
299-
Effect.catchTag("ServerAuthInvalidCredentialError", () =>
300-
Effect.succeed({
301-
authenticated: false,
302-
auth: descriptor,
303-
} satisfies AuthSessionState),
304-
),
299+
Effect.catchTags({
300+
ServerAuthInvalidCredentialError: () =>
301+
Effect.succeed({
302+
authenticated: false,
303+
auth: descriptor,
304+
} satisfies AuthSessionState),
305+
ServerAuthInternalError: () =>
306+
Effect.succeed({
307+
authenticated: false,
308+
auth: descriptor,
309+
} satisfies AuthSessionState),
310+
}),
305311
);
306312

307313
const createBrowserSession: EnvironmentAuthShape["createBrowserSession"] = (

apps/server/src/auth/http.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,7 @@ export const authHttpApiLayer = HttpApiBuilder.group(
167167
Effect.fn("environment.auth.session")(function* (args) {
168168
yield* annotateEnvironmentRequest(args.endpoint.name);
169169
const request = yield* HttpServerRequest.HttpServerRequest;
170-
return yield* serverAuth
171-
.getSessionState(request)
172-
.pipe(
173-
Effect.catchTag("ServerAuthInternalError", (error) =>
174-
failEnvironmentInternal("internal_error", error),
175-
),
176-
);
170+
return yield* serverAuth.getSessionState(request);
177171
}),
178172
)
179173
.handle(

0 commit comments

Comments
 (0)