Skip to content

Commit 9c71d53

Browse files
committed
chore: remove utils/api
1 parent 699937f commit 9c71d53

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/lib/api.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
import { API_URL } from "@/constants/api"
12
import { BALANCES, INFO } from "@/constants/endpoints"
2-
import { apiFetch } from "@/utils/api"
3+
4+
const apiFetch = async <T = unknown>(endpoint: string, options: RequestInit = {}): Promise<T> => {
5+
const url = `${API_URL}${endpoint}`
6+
7+
const response = await fetch(url, {
8+
...options,
9+
/* headers: {
10+
"Content-Type": "application/json",
11+
...(options.headers || {}),
12+
}, */
13+
headers: options.headers ?? [],
14+
})
15+
16+
if (!response.ok) {
17+
throw new Error(`HTTP error! status: ${response.statusText}`)
18+
}
19+
20+
const contentLength = response.headers.get("Content-Length")
21+
22+
if (contentLength === "0" || response.headers.get("Content-Type")?.includes("application/json") === false) {
23+
return {} as T
24+
}
25+
26+
return response.json() as Promise<T>
27+
}
328

429
export interface InfoResponse {
530
name?: string

src/utils/api.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)