File tree Expand file tree Collapse file tree 2 files changed +26
-27
lines changed Expand file tree Collapse file tree 2 files changed +26
-27
lines changed Original file line number Diff line number Diff line change
1
+ import { API_URL } from "@/constants/api"
1
2
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
+ }
3
28
4
29
export interface InfoResponse {
5
30
name ?: string
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments