@vigneshreddy/cms-sdk 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/errors.js +14 -4
- package/package.json +1 -1
package/dist/src/errors.js
CHANGED
|
@@ -29,6 +29,12 @@ function handleApiError(error, request, response) {
|
|
|
29
29
|
if (error instanceof base_1.CMSAPIError) {
|
|
30
30
|
throw error; // preserve original error metadata/type
|
|
31
31
|
}
|
|
32
|
+
const isHtmlResponse = (data) => {
|
|
33
|
+
if (typeof data !== "string")
|
|
34
|
+
return false;
|
|
35
|
+
const trimmed = data.trim().toLowerCase();
|
|
36
|
+
return trimmed.startsWith("<!doctype") || trimmed.startsWith("<html") || trimmed.startsWith("<!-");
|
|
37
|
+
};
|
|
32
38
|
const getBackendErrorMessage = (data) => {
|
|
33
39
|
var _a;
|
|
34
40
|
const directMessage = typeof (data === null || data === void 0 ? void 0 : data.message) === "string" ? data.message.trim() : "";
|
|
@@ -55,7 +61,8 @@ function handleApiError(error, request, response) {
|
|
|
55
61
|
return firstObjectErrorText.errorMessage.trim();
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
// Ignore HTML responses (e.g., 404 pages)
|
|
65
|
+
if (typeof data === "string" && data.trim() && !isHtmlResponse(data)) {
|
|
59
66
|
return data.trim();
|
|
60
67
|
}
|
|
61
68
|
return undefined;
|
|
@@ -78,16 +85,19 @@ function handleApiError(error, request, response) {
|
|
|
78
85
|
if (errorWithResponse) {
|
|
79
86
|
const res = errorWithResponse;
|
|
80
87
|
const statusCode = (_c = (_b = res.status) !== null && _b !== void 0 ? _b : res.statusCode) !== null && _c !== void 0 ? _c : 500;
|
|
81
|
-
const
|
|
88
|
+
const isHtml = isHtmlResponse(res.data);
|
|
89
|
+
const backendMessage = isHtml ? undefined : getBackendErrorMessage(res.data);
|
|
82
90
|
const fallbackMessage = `CMS API Error: ${statusCode} - ${(_d = res.statusText) !== null && _d !== void 0 ? _d : "Unknown API Error"}`;
|
|
83
91
|
const message = backendMessage !== null && backendMessage !== void 0 ? backendMessage : fallbackMessage;
|
|
92
|
+
// Don't pass HTML blobs as rawError
|
|
93
|
+
const rawError = isHtml ? undefined : ((_e = res.data) !== null && _e !== void 0 ? _e : error);
|
|
84
94
|
// Prefer typed error subclasses when possible
|
|
85
|
-
const typedError = (0, specific_1.createSpecificError)(statusCode, message,
|
|
95
|
+
const typedError = (0, specific_1.createSpecificError)(statusCode, message, rawError);
|
|
86
96
|
typedError.request = sanitizeRequest(request !== null && request !== void 0 ? request : error === null || error === void 0 ? void 0 : error.request);
|
|
87
97
|
typedError.response = {
|
|
88
98
|
status: statusCode,
|
|
89
99
|
statusText: res.statusText || "",
|
|
90
|
-
data: res.data,
|
|
100
|
+
data: isHtml ? undefined : res.data,
|
|
91
101
|
headers: res.headers,
|
|
92
102
|
};
|
|
93
103
|
throw typedError;
|