mirror of
https://github.com/hubHarmony/servii-frontend.git
synced 2024-11-17 21:40:30 +00:00
[+] Added maintenance toast
This commit is contained in:
parent
f52930bce4
commit
7edcbe3653
@ -59,30 +59,8 @@ const nonToastableCalls: string[] = [
|
||||
serviiRequest.fetchPlayersStatus,
|
||||
];
|
||||
|
||||
class serviiApi {
|
||||
constructor() {}
|
||||
|
||||
private static async call<T extends BaseRequest>(endpoint: serviiRequest, body: T): Promise<ApiResponse> {
|
||||
const response = await fetch(`${apiUrl}/${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const status: number = response.status;
|
||||
const json = await response.json();
|
||||
|
||||
if (json.message === undefined) {
|
||||
if (!(endpoint === serviiRequest.fetchServers)) {
|
||||
return { return_code: status, message: "Couldn't find an available API" };
|
||||
}
|
||||
return { return_code: status, message: json };
|
||||
}
|
||||
|
||||
if (!nonToastableCalls.includes(endpoint)) {
|
||||
|
||||
let toastType: 'success' | 'error' | 'info';
|
||||
function toast_status(status: number, message: string) {
|
||||
let toastType: 'success' | 'error' | 'info' | 'warning';
|
||||
|
||||
if (status >= 200 && status < 300) {
|
||||
toastType = 'success';
|
||||
@ -91,8 +69,11 @@ class serviiApi {
|
||||
} else {
|
||||
toastType = 'info';
|
||||
}
|
||||
if (status == 666) {
|
||||
toastType = 'warning';
|
||||
}
|
||||
|
||||
toast[toastType](json.message, {
|
||||
toast[toastType](message, {
|
||||
position: "top-right",
|
||||
autoClose: 3500,
|
||||
hideProgressBar: false,
|
||||
@ -103,11 +84,43 @@ class serviiApi {
|
||||
theme: "light",
|
||||
transition: Bounce,
|
||||
});
|
||||
}
|
||||
|
||||
class serviiApi {
|
||||
private static async call<T extends BaseRequest>(endpoint: serviiRequest, body: T): Promise<ApiResponse> {
|
||||
const unreachable: string = "Couldn't find an available API";
|
||||
try {
|
||||
const response = await fetch(`${apiUrl}/${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const status: number = response.status;
|
||||
const json = await response.json();
|
||||
const message = json.message;
|
||||
|
||||
if (message === undefined) {
|
||||
if (!(endpoint === serviiRequest.fetchServers)) {
|
||||
return {return_code: 503, message: "Couldn't find an available API"};
|
||||
}
|
||||
return {return_code: status, message: json};
|
||||
}
|
||||
|
||||
return { return_code: status, message: json.message };
|
||||
if (!nonToastableCalls.includes(endpoint)) {
|
||||
toast_status(status, message);
|
||||
}
|
||||
|
||||
return {return_code: status, message: json.message};
|
||||
} catch (error) {
|
||||
toast_status(666, unreachable);
|
||||
return {return_code: 503, message: "Couldn't find an available API"}
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
|
||||
private static token(): string {
|
||||
const currentUser = getAuth().currentUser;
|
||||
if (!currentUser) {
|
||||
|
Loading…
Reference in New Issue
Block a user