Redirect to login on mid-session 401 instead of silently failing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a39b131e6a
commit
f8847c0726
1 changed files with 8 additions and 0 deletions
|
|
@ -7,6 +7,10 @@ async function req<T>(method: string, path: string, body?: unknown): Promise<T>
|
||||||
headers: body ? { 'Content-Type': 'application/json' } : undefined,
|
headers: body ? { 'Content-Type': 'application/json' } : undefined,
|
||||||
body: body ? JSON.stringify(body) : undefined,
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
})
|
})
|
||||||
|
if (res.status === 401) {
|
||||||
|
;(window.top ?? window).location.href = '/login'
|
||||||
|
throw new Error('Unauthenticated')
|
||||||
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = await res.json().catch(() => ({ error: res.statusText }))
|
const err = await res.json().catch(() => ({ error: res.statusText }))
|
||||||
throw new Error((err as { error?: string }).error || res.statusText)
|
throw new Error((err as { error?: string }).error || res.statusText)
|
||||||
|
|
@ -36,6 +40,10 @@ export async function uploadAttachment(
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: fd,
|
body: fd,
|
||||||
})
|
})
|
||||||
|
if (res.status === 401) {
|
||||||
|
;(window.top ?? window).location.href = '/login'
|
||||||
|
throw new Error('Unauthenticated')
|
||||||
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = await res.json().catch(() => ({ error: res.statusText }))
|
const err = await res.json().catch(() => ({ error: res.statusText }))
|
||||||
throw new Error((err as { error?: string }).error || res.statusText)
|
throw new Error((err as { error?: string }).error || res.statusText)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue