プリフェッチ実装(#140) (#256)
Merge branch 'main' into feature/140 #140 Merge remote-tracking branch 'origin/main' into feature/140 #140 #140 #140 #140 #140 Merge remote-tracking branch 'origin/main' into feature/140 #140 #140 #140 #140 #140 #140 #140 #140 #140 #140 #140 Merge remote-tracking branch 'origin/main' into feature/140 Merge remote-tracking branch 'origin/main' into feature/140 #140 ぼちぼち Merge remote-tracking branch 'origin/main' into feature/140 #140 #140 #140 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #256
This commit was merged in pull request #256.
This commit is contained in:
+12
-2
@@ -3,9 +3,12 @@ import toCamel from 'camelcase-keys'
|
||||
|
||||
import { API_BASE_URL } from '@/config'
|
||||
|
||||
import type { AxiosError, AxiosRequestConfig } from 'axios'
|
||||
|
||||
type Opt = {
|
||||
params?: Record<string, unknown>
|
||||
headers?: Record<string, string> }
|
||||
params?: AxiosRequestConfig['params']
|
||||
headers?: Record<string, string>
|
||||
responseType?: 'blob' }
|
||||
|
||||
const client = axios.create ({ baseURL: API_BASE_URL })
|
||||
|
||||
@@ -23,6 +26,8 @@ const apiP = async <T> (
|
||||
opt?: Opt,
|
||||
): Promise<T> => {
|
||||
const res = await client[method] (path, body ?? { }, withUserCode (opt))
|
||||
if (opt?.responseType === 'blob')
|
||||
return res.data as T
|
||||
return toCamel (res.data as any, { deep: true }) as T
|
||||
}
|
||||
|
||||
@@ -32,6 +37,8 @@ export const apiGet = async <T> (
|
||||
opt?: Opt,
|
||||
): Promise<T> => {
|
||||
const res = await client.get (path, withUserCode (opt))
|
||||
if (opt?.responseType === 'blob')
|
||||
return res.data as T
|
||||
return toCamel (res.data as any, { deep: true }) as T
|
||||
}
|
||||
|
||||
@@ -63,3 +70,6 @@ export const apiDelete = async (
|
||||
): Promise<void> => {
|
||||
await client.delete (path, withUserCode (opt))
|
||||
}
|
||||
|
||||
|
||||
export const isApiError = (err: unknown): err is AxiosError => axios.isAxiosError (err)
|
||||
|
||||
Reference in New Issue
Block a user