mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 07:03:25 +00:00
feat: recreate dashboard page from previous version
This commit is contained in:
24
inertia/lib/request.ts
Normal file
24
inertia/lib/request.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import i18n from '~/i18n';
|
||||
|
||||
export async function makeRequest({
|
||||
method = 'GET',
|
||||
url,
|
||||
body,
|
||||
}: {
|
||||
method?: RequestInit['method'];
|
||||
url: string;
|
||||
body?: object | any[];
|
||||
}): Promise<any> {
|
||||
const request = await fetch(url, {
|
||||
method,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const data = await request.json();
|
||||
return request.ok
|
||||
? data
|
||||
: Promise.reject(data?.error || i18n.t('common:generic-error'));
|
||||
}
|
||||
Reference in New Issue
Block a user