harden sse errors

This commit is contained in:
2026-08-23 17:35:45 -07:00
parent 98343e55d1
commit d0507481cb
2 changed files with 19 additions and 8 deletions
+19 -6
View File
@@ -159,16 +159,29 @@ export function useServerEvents() {
logger.error("SSE connection error", error);
disconnect();
// The stream is auth-guarded, so an error is often the server rejecting
// an expired session rather than a network blip. Try to refresh; if the
// session is genuinely gone, stop retrying so we don't hammer the
// endpoint forever — a real re-login (or a wake event) will reconnect.
let sessionValid = true;
try {
const { attemptRefreshingSession } = await import('supertokens-web-js/recipe/session');
sessionValid = await attemptRefreshingSession();
} catch {
// Refresh call itself failed (likely offline) — treat as transient.
}
if (disposed) return;
if (!sessionValid) {
logger.warn("SSE stopped: session is no longer valid");
return;
}
retryCount += 1;
const delay = Math.min(1000 * Math.pow(1.5, retryCount - 1), 15000);
logger.info(`SSE reconnection attempt ${retryCount} in ${Math.round(delay)}ms`);
try {
const { attemptRefreshingSession } = await import('supertokens-web-js/recipe/session');
await attemptRefreshingSession();
} catch {
}
reconnect(delay);
};
};
-2
View File
@@ -60,7 +60,6 @@ const verifySuperTokensSession = async (request: Request) => {
const userAuthId = session?.userId;
if (!userAuthId || !session) {
logger.info("No authenticated user");
return { context: { userAuthId: null, roles: [] } };
}
@@ -109,7 +108,6 @@ export const getSessionContextCore = async (
}
if (!session.context.userAuthId) {
logger.error("Unauthenticated user", session.context);
throw new Error("Unauthenticated");
}