use logger

This commit is contained in:
Zamitto 2024-06-19 00:09:13 -03:00
parent 2e5a324669
commit 3b2b78dc7c

View File

@ -4,6 +4,7 @@ import { WindowManager } from "./window-manager";
import url from "url";
import { uploadGamesBatch } from "./library-sync";
import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id";
import { logger } from "./logger";
export class HydraApi {
private static instance: AxiosInstance;
@ -63,20 +64,20 @@ export class HydraApi {
this.instance.interceptors.request.use(
(request) => {
console.log(" ---- REQUEST -----");
console.log(request.method, request.url, request.data);
logger.log(" ---- REQUEST -----");
logger.log(request.method, request.url, request.data);
return request;
},
(error) => {
console.log("request error", error);
logger.log("request error", error);
return Promise.reject(error);
}
);
this.instance.interceptors.response.use(
(response) => {
console.log(" ---- RESPONSE -----");
console.log(
logger.log(" ---- RESPONSE -----");
logger.log(
response.status,
response.config.method,
response.config.url,
@ -85,7 +86,7 @@ export class HydraApi {
return response;
},
(error) => {
console.log("response error", error);
logger.error("response error", error);
return Promise.reject(error);
}
);
@ -104,6 +105,7 @@ export class HydraApi {
private static async revalidateAccessTokenIfExpired() {
if (!this.userAuth.authToken) {
userAuthRepository.delete({ id: 1 });
logger.error("user is not logged in");
throw new Error("user is not logged in");
}
@ -146,6 +148,8 @@ export class HydraApi {
if (WindowManager.mainWindow) {
WindowManager.mainWindow.webContents.send("on-signout");
}
logger.log("user refresh token expired");
}
throw err;