mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
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:
@@ -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) => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user