maplestory/frontend/src/api/client.js

16 lines
424 B
JavaScript
Raw Normal View History

export async function api(url, options = {}) {
const res = await fetch(url, {
credentials: 'include',
headers: { 'Content-Type': 'application/json', ...options.headers },
...options,
body: options.body ? JSON.stringify(options.body) : undefined,
})
if (!res.ok) {
const error = await res.json().catch(() => ({}))
throw new Error(error.error || `HTTP ${res.status}`)
}
return res.json()
}