This commit is contained in:
2026-06-10 07:55:16 +08:00
parent 821eca9f0c
commit aaac7e9d98
31 changed files with 548 additions and 149 deletions
+5
View File
@@ -11,13 +11,16 @@ interface RequestOptions {
let authTokenProvider: () => string | null = () => null
let onUnauthorized: () => void = () => {}
let onForbidden: () => void = () => {}
export function configure(opts: {
tokenProvider: () => string | null
onUnauthorized: () => void
onForbidden?: () => void
}) {
authTokenProvider = opts.tokenProvider
onUnauthorized = opts.onUnauthorized
if (opts.onForbidden) onForbidden = opts.onForbidden
}
export async function request<T>(path: string, opts: RequestOptions = {}): Promise<T> {
@@ -55,6 +58,8 @@ export async function request<T>(path: string, opts: RequestOptions = {}): Promi
if (resp.status === 401) {
onUnauthorized()
} else if (resp.status === 403) {
onForbidden()
}
if (resp.status === 204) {