feat: now compliant with eslint
All checks were successful
CI / build (push) Successful in 10s

This commit is contained in:
Pierre Tellier
2025-02-09 15:28:09 +01:00
parent 8af40bfe50
commit 1dff7573ff
13 changed files with 72 additions and 65 deletions

View File

@ -1,4 +1,4 @@
import axios from "axios";
import axios, {type AxiosError, type AxiosResponse} from "axios";
import {store} from "@/main.ts";
import {addNewMessage, color} from "@/services/popupDisplayer.ts";
@ -34,21 +34,18 @@ axiosInstance.interceptors.response.use(
);
// TODO: spawn a error modal
function defaultApiErrorHandler(err: string){
addNewMessage(err, color.Red);
function defaultApiErrorHandler(err: AxiosError){
addNewMessage(err.message, color.Red);
}
function defaultApiSuccessHandler(response: any){
addNewMessage(response.data, color.green)
function defaultApiSuccessHandler(response: AxiosResponse){
addNewMessage(response.data, color.Green)
}
function callApi(endpoint: string, onSuccessHandler?: any, onErrorHandler?: any): void {
function callApi(endpoint: string, onSuccessHandler?: (response: AxiosResponse) => void, onErrorHandler?: (error: AxiosError) => void): void {
axiosInstance.get(endpoint).then(
onSuccessHandler == null ? defaultApiSuccessHandler : onSuccessHandler
).catch(
(err) => {
onErrorHandler == null ? defaultApiErrorHandler(err): onErrorHandler(err);
throw err;
}
onErrorHandler == null ? defaultApiErrorHandler: onErrorHandler
)
}