frontend performance, rpc/rest jwt authentication
This commit is contained in:
21
frontend/src/lib/httpClient.ts
Normal file
21
frontend/src/lib/httpClient.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as E from 'fp-ts/Either'
|
||||
import { pipe } from 'fp-ts/function'
|
||||
|
||||
type FetchInit = {
|
||||
url: string,
|
||||
opt?: RequestInit
|
||||
}
|
||||
|
||||
export async function ffetch<T>(
|
||||
url: string,
|
||||
onSuccess: (res: T) => void,
|
||||
onError: (err: string) => void,
|
||||
opt?: RequestInit,
|
||||
) {
|
||||
const res = await fetch(url, opt)
|
||||
if (!res.ok) {
|
||||
onError(await res.text())
|
||||
return
|
||||
}
|
||||
onSuccess(await res.json() as T)
|
||||
}
|
||||
Reference in New Issue
Block a user