diff --git a/utils/Fetch.ts b/utils/Fetch.ts new file mode 100644 index 0000000..47f5d2d --- /dev/null +++ b/utils/Fetch.ts @@ -0,0 +1,20 @@ +import { ResponseProps } from '@types' +import { KoreanbotsEndPoints } from './Constants' + +const Fetch = async (endpoint: string, options?: RequestInit):Promise> => { + 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 \ No newline at end of file