Restructuring the Project
Updating dependencies
This commit is contained in:
26
FrontendLegacy/shared/request.js
Normal file
26
FrontendLegacy/shared/request.js
Normal file
@ -0,0 +1,26 @@
|
||||
export default function request(endpoint, method, data) {
|
||||
var headers = new Headers();
|
||||
headers.set("Content-Type", "application/json");
|
||||
return fetch(endpoint, {
|
||||
method: method,
|
||||
body: JSON.stringify(data),
|
||||
headers: headers,
|
||||
credentials: "include",
|
||||
})
|
||||
.then(async (e) => {
|
||||
if (e.status !== 200)
|
||||
throw new Error((await e.text()) || e.statusText);
|
||||
return e.json();
|
||||
})
|
||||
.then((e) => {
|
||||
if (e.error)
|
||||
return Promise.reject(
|
||||
new Error(
|
||||
typeof e.error === "string"
|
||||
? e.error
|
||||
: JSON.stringify(e.error)
|
||||
)
|
||||
);
|
||||
return e;
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user