mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 06:10:22 +00:00
25 lines
583 B
TypeScript
25 lines
583 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, {
|
|
method: 'GET',
|
|
headers: { 'content-type': 'application/json', ...options.headers },
|
|
...options,
|
|
})
|
|
|
|
let json = {}
|
|
|
|
try {
|
|
json = await res.json()
|
|
} catch {
|
|
json = { code: 500, message: 'Internal Server Error' }
|
|
}
|
|
|
|
return json
|
|
}
|
|
|
|
export default Fetch
|