first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export async function apiRequest(path, options = {}) {
|
||||
const response = await fetch(path, {
|
||||
...options,
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
...(options.body ? { 'content-type': 'application/json' } : {}),
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/login');
|
||||
throw new Error('로그인이 필요합니다.');
|
||||
}
|
||||
|
||||
if (response.status === 204) return null;
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.error?.message ?? '요청을 처리하지 못했습니다.');
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user