mirror of
https://github.com/koreanbots/core.git
synced 2025-12-16 14:30:22 +00:00
20 lines
505 B
TypeScript
20 lines
505 B
TypeScript
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 |