feature: Degraded Operations Visibility
This commit is contained in:
@@ -52,4 +52,30 @@ export const api = {
|
||||
method: 'POST',
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
}),
|
||||
put: (path, body) => request(path, {
|
||||
method: 'PUT',
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
}),
|
||||
patch: (path, body) => request(path, {
|
||||
method: 'PATCH',
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
}),
|
||||
delete: async (path) => {
|
||||
const res = await fetch(`${BASE_URL}${path}`, {
|
||||
method: 'DELETE',
|
||||
headers: authHeaders(),
|
||||
})
|
||||
if (res.status === 401) {
|
||||
throw new Error('Session expired — please log in again.')
|
||||
}
|
||||
if (res.status === 204) return null
|
||||
const envelope = await res.json()
|
||||
if (!res.ok || !envelope.success) {
|
||||
const msg = envelope.error?.message ?? `API ${res.status}: ${path}`
|
||||
throw new Error(msg)
|
||||
}
|
||||
return envelope.data ?? null
|
||||
},
|
||||
}
|
||||
|
||||
export { BASE_URL, authHeaders }
|
||||
|
||||
Reference in New Issue
Block a user