@vigneshreddy/cms-sdk 1.0.12 → 1.0.13

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.
@@ -20,4 +20,8 @@ export declare class CMSAPIError extends Error {
20
20
  headers?: Record<string, any>;
21
21
  };
22
22
  constructor(message: string, statusCode: number, type: string, rawError: any, request?: CMSAPIError["request"], response?: CMSAPIError["response"]);
23
+ toJSON(): {
24
+ statusCode: number;
25
+ message: string;
26
+ };
23
27
  }
@@ -12,7 +12,10 @@ class CMSAPIError extends Error {
12
12
  this.statusCode = statusCode;
13
13
  this.type = type;
14
14
  this.rawError = rawError;
15
- this.cause = rawError;
15
+ this.cause =
16
+ rawError instanceof Error || typeof rawError === "string"
17
+ ? rawError
18
+ : undefined;
16
19
  this.request = request;
17
20
  this.response = response;
18
21
  // Ensure proper prototype chain in transpiled output
@@ -35,5 +38,11 @@ class CMSAPIError extends Error {
35
38
  // it will just remain enumerable.
36
39
  }
37
40
  }
41
+ toJSON() {
42
+ return {
43
+ statusCode: this.statusCode,
44
+ message: this.message,
45
+ };
46
+ }
38
47
  }
39
48
  exports.CMSAPIError = CMSAPIError;
@@ -38,6 +38,10 @@ function handleApiError(error, request, response) {
38
38
  if (nestedMessage)
39
39
  return nestedMessage;
40
40
  if (Array.isArray(data === null || data === void 0 ? void 0 : data.errors)) {
41
+ const firstObjectErrorCode = data.errors.find((item) => typeof (item === null || item === void 0 ? void 0 : item.code) === "string" && item.code.trim());
42
+ if (firstObjectErrorCode) {
43
+ return firstObjectErrorCode.code.trim();
44
+ }
41
45
  const firstStringError = data.errors.find((item) => typeof item === "string" && item.trim());
42
46
  if (typeof firstStringError === "string") {
43
47
  return firstStringError.trim();
@@ -46,6 +50,10 @@ function handleApiError(error, request, response) {
46
50
  if (firstObjectErrorMessage) {
47
51
  return firstObjectErrorMessage.message.trim();
48
52
  }
53
+ const firstObjectErrorText = data.errors.find((item) => typeof (item === null || item === void 0 ? void 0 : item.errorMessage) === "string" && item.errorMessage.trim());
54
+ if (firstObjectErrorText) {
55
+ return firstObjectErrorText.errorMessage.trim();
56
+ }
49
57
  }
50
58
  if (typeof data === "string" && data.trim()) {
51
59
  return data.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vigneshreddy/cms-sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Official TypeScript SDK for CutMeShort CMS API",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",