mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2026-02-05 10:44:11 +02:00
add auth service
This commit is contained in:
21
luckydiamond/src/assets/js/rest/RestMethods.js
Normal file
21
luckydiamond/src/assets/js/rest/RestMethods.js
Normal file
@@ -0,0 +1,21 @@
|
||||
export async function Post(url = "", data = {}) {
|
||||
// Default options are marked with *
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
redirect: "follow",
|
||||
referrerPolicy: "no-referrer",
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.log("Fetch error:", error);
|
||||
throw error; // Re-throw the error so it can be caught by the calling function
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user