mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
fix: error handling
This commit is contained in:
parent
540fd80d91
commit
5ac0c04c69
@ -154,7 +154,8 @@ export class HydraApi {
|
|||||||
(error) => {
|
(error) => {
|
||||||
logger.error(" ---- RESPONSE ERROR -----");
|
logger.error(" ---- RESPONSE ERROR -----");
|
||||||
const { config } = error;
|
const { config } = error;
|
||||||
const data = JSON.parse(config.data);
|
|
||||||
|
const data = JSON.parse(config.data ?? null);
|
||||||
|
|
||||||
logger.error(
|
logger.error(
|
||||||
config.method,
|
config.method,
|
||||||
@ -175,14 +176,22 @@ export class HydraApi {
|
|||||||
error.response.status,
|
error.response.status,
|
||||||
error.response.data
|
error.response.data
|
||||||
);
|
);
|
||||||
} else if (error.request) {
|
|
||||||
const errorData = error.toJSON();
|
return Promise.reject(error as Error);
|
||||||
logger.error("Request error:", errorData.message);
|
|
||||||
} else {
|
|
||||||
logger.error("Error", error.message);
|
|
||||||
}
|
}
|
||||||
logger.error(" ----- END RESPONSE ERROR -------");
|
|
||||||
return Promise.reject(error);
|
if (error.request) {
|
||||||
|
const errorData = error.toJSON();
|
||||||
|
logger.error("Request error:", errorData.code, errorData.message);
|
||||||
|
return Promise.reject(
|
||||||
|
new Error(
|
||||||
|
`Request failed with ${errorData.code} ${errorData.message}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Error", error.message);
|
||||||
|
return Promise.reject(error as Error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -262,7 +271,7 @@ export class HydraApi {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static handleUnauthorizedError = (err) => {
|
private static readonly handleUnauthorizedError = (err) => {
|
||||||
if (err instanceof AxiosError && err.response?.status === 401) {
|
if (err instanceof AxiosError && err.response?.status === 401) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"401 - Current credentials:",
|
"401 - Current credentials:",
|
||||||
|
Loading…
Reference in New Issue
Block a user