fix: Simplify error response handling in API class

This commit is contained in:
Nawaz Dhandala
2026-03-18 13:13:33 +00:00
parent 4375e1c8fd
commit 65a4132081

View File

@@ -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>,
);
}