mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix: Simplify error response handling in API class
This commit is contained in:
@@ -518,20 +518,9 @@ export default class API {
|
||||
|
||||
private static getErrorResponse(error: AxiosError): HTTPErrorResponse {
|
||||
if (error.response) {
|
||||
let responseData: JSONObject | JSONArray =
|
||||
error.response.data as JSONObject | JSONArray;
|
||||
|
||||
// If the response data is a string (e.g. HTML error page from a proxy like Cloudflare),
|
||||
// convert it to a JSON object with a friendly error message instead of raw HTML.
|
||||
if (typeof error.response.data === "string") {
|
||||
responseData = {
|
||||
error: `Server returned ${error.response.status} ${error.response.statusText || "Error"}`,
|
||||
};
|
||||
}
|
||||
|
||||
return new HTTPErrorResponse(
|
||||
error.response.status,
|
||||
responseData,
|
||||
error.response.data as JSONObject | JSONArray,
|
||||
error.response.headers as Dictionary<string>,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user