Fix preview lease claim error handling

This commit is contained in:
Madison 2026-05-28 12:31:31 -05:00
parent 46e3935fb4
commit e1692c12bf

View File

@ -5,6 +5,7 @@ import { useRouter } from "@/components/router";
import { getPublicEnvVar } from "@/lib/env";
import { stackAppInternalsSymbol } from "@/lib/stack-app-internals";
import { useStackApp, useUser, type CurrentInternalUser } from "@stackframe/stack";
import { HexclaveAssertionError } from "@stackframe/stack-shared/dist/utils/errors";
import { runAsynchronouslyWithAlert } from "@stackframe/stack-shared/dist/utils/promises";
import { usePathname } from "next/navigation";
import { useEffect, useRef } from "react";
@ -89,7 +90,10 @@ async function claimPreviewLease(app: unknown): Promise<PreviewLeaseResponse> {
);
if (!response.ok) {
throw new Error(`Failed to claim preview lease: ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`);
throw new HexclaveAssertionError(
`Failed to claim preview lease: ${response.status}${response.statusText ? ` ${response.statusText}` : ""}`,
{ status: response.status, statusText: response.statusText },
);
}
return parsePreviewLeaseResponse(await response.json());
@ -111,6 +115,10 @@ function PreviewLeaseClaimGate() {
refreshToken: lease.refreshToken,
});
await internals.refreshOwnedProjects();
}, {
onError: () => {
claimStarted.current = false;
},
});
}, [app]);