mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 22:30:23 +00:00
feat: added Fetch function
This commit is contained in:
parent
9fa0e2000f
commit
e5b576fec7
20
utils/Fetch.ts
Normal file
20
utils/Fetch.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { ResponseProps } from '@types'
|
||||
import { KoreanbotsEndPoints } from './Constants'
|
||||
|
||||
const Fetch = async <T>(endpoint: string, options?: RequestInit):Promise<ResponseProps<T>> => {
|
||||
const url = KoreanbotsEndPoints.baseAPI + ( endpoint.startsWith('/') ? endpoint : '/' + endpoint)
|
||||
|
||||
const res = await fetch(url, options ?? { method: 'GET' })
|
||||
|
||||
let json = {}
|
||||
|
||||
try {
|
||||
json = await res.json()
|
||||
} catch {
|
||||
json = { code: 500, message: (await res.text()) }
|
||||
}
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
export default Fetch
|
||||
Loading…
x
Reference in New Issue
Block a user