fix(cloud): EP-9 a 403 not_a_member on the billing mint is a team-switch error, not a session failure

This commit is contained in:
Neil
2026-11-13 05:31:42 -08:00
parent de4286aa73
commit bb79de4bc7
2 changed files with 13 additions and 1 deletions
+6
View File
@@ -80,6 +80,12 @@ describe('billing client', () => {
await expect(mintBillingToken(endpoints, 'a', null, fetchImpl)).rejects.toBeInstanceOf(BillingOrgMismatchError)
})
it('treats 403 not_a_member as a team-switch error, not a session failure', async () => {
const fetchImpl: typeof fetch = async () =>
new Response(JSON.stringify({ error: 'not_a_member' }), { status: 403 })
await expect(mintBillingToken(endpoints, 'a', 'org_gone', fetchImpl)).rejects.toBeInstanceOf(BillingOrgMismatchError)
})
it('falls back to the empty body on an older auth (400), still checking the claim', async () => {
const bodies: Array<string | undefined> = []
const fetchImpl: typeof fetch = async (_input, init) => {
+7 -1
View File
@@ -103,7 +103,13 @@ export async function mintBillingToken(
response = await post('{}')
}
if (!response.ok) {
throw new OrcaCloudRequestError(response.status, (await readErrorCode(response)) ?? undefined)
const code = (await readErrorCode(response)) ?? undefined
if (response.status === 403 && orgId && code === 'not_a_member') {
// This device shows a team the person is no longer on: a switch error, not a session one
// (refreshing the session would not help).
throw new BillingOrgMismatchError(orgId)
}
throw new OrcaCloudRequestError(response.status, code)
}
const body = TokenBody.safeParse(await response.json())
if (!body.success) {