@gymspace/evolution 1.2.5 → 1.3.1
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/index.js +92 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -32,8 +32,9 @@ var EvolutionApiError = class _EvolutionApiError extends Error {
|
|
|
32
32
|
this.message = finalMessage;
|
|
33
33
|
this.statusCode = statusCode;
|
|
34
34
|
this.details = cause;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const ErrorConstructor = Error;
|
|
36
|
+
if (typeof ErrorConstructor.captureStackTrace === "function") {
|
|
37
|
+
ErrorConstructor.captureStackTrace(this, _EvolutionApiError);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -47,18 +48,18 @@ var EvolutionApiError = class _EvolutionApiError extends Error {
|
|
|
47
48
|
if (this.details && typeof this.details === "object") {
|
|
48
49
|
const details = this.details;
|
|
49
50
|
const relevantDetails = [];
|
|
50
|
-
if (details.url) {
|
|
51
|
+
if (typeof details.url === "string") {
|
|
51
52
|
relevantDetails.push(`URL: ${details.url}`);
|
|
52
53
|
}
|
|
53
|
-
if (details.method) {
|
|
54
|
+
if (typeof details.method === "string") {
|
|
54
55
|
relevantDetails.push(`Method: ${details.method}`);
|
|
55
56
|
}
|
|
56
57
|
if (details.response && typeof details.response === "object") {
|
|
57
58
|
const response = details.response;
|
|
58
|
-
if (response.error && response.error !== this.message) {
|
|
59
|
+
if (typeof response.error === "string" && response.error !== this.message) {
|
|
59
60
|
relevantDetails.push(`Server Error: ${response.error}`);
|
|
60
61
|
}
|
|
61
|
-
if (response.message && response.message !== this.message) {
|
|
62
|
+
if (typeof response.message === "string" && response.message !== this.message) {
|
|
62
63
|
relevantDetails.push(`Server Message: ${response.message}`);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -82,6 +83,17 @@ var EvolutionApiError = class _EvolutionApiError extends Error {
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
};
|
|
86
|
+
function getNestedProperty(obj, path) {
|
|
87
|
+
let current = obj;
|
|
88
|
+
for (const key of path) {
|
|
89
|
+
if (current && typeof current === "object" && key in current) {
|
|
90
|
+
current = current[key];
|
|
91
|
+
} else {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return current;
|
|
96
|
+
}
|
|
85
97
|
function extractErrorMessage(response) {
|
|
86
98
|
if (!response) {
|
|
87
99
|
return null;
|
|
@@ -92,45 +104,93 @@ function extractErrorMessage(response) {
|
|
|
92
104
|
if (typeof response === "object" && response !== null) {
|
|
93
105
|
try {
|
|
94
106
|
const errorObj = response;
|
|
95
|
-
const
|
|
107
|
+
const checkPaths = [
|
|
96
108
|
// Evolution API specific nested structure (most common)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
() => {
|
|
110
|
+
const val = getNestedProperty(errorObj, ["response", "response", "message"]);
|
|
111
|
+
if (Array.isArray(val) && val.length > 0) return String(val[0]);
|
|
112
|
+
return null;
|
|
113
|
+
},
|
|
114
|
+
() => {
|
|
115
|
+
const val = getNestedProperty(errorObj, ["response", "response", "error"]);
|
|
116
|
+
return typeof val === "string" ? val : null;
|
|
117
|
+
},
|
|
118
|
+
() => {
|
|
119
|
+
const val = getNestedProperty(errorObj, ["response", "response", "description"]);
|
|
120
|
+
return typeof val === "string" ? val : null;
|
|
121
|
+
},
|
|
100
122
|
// Evolution API first level nested
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
() => {
|
|
124
|
+
const val = getNestedProperty(errorObj, ["response", "message"]);
|
|
125
|
+
if (Array.isArray(val) && val.length > 0) return String(val[0]);
|
|
126
|
+
return null;
|
|
127
|
+
},
|
|
128
|
+
() => {
|
|
129
|
+
const val = getNestedProperty(errorObj, ["response", "error"]);
|
|
130
|
+
return typeof val === "string" ? val : null;
|
|
131
|
+
},
|
|
132
|
+
() => {
|
|
133
|
+
const val = getNestedProperty(errorObj, ["response", "description"]);
|
|
134
|
+
return typeof val === "string" ? val : null;
|
|
135
|
+
},
|
|
104
136
|
// Direct error message
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
137
|
+
() => {
|
|
138
|
+
const val = errorObj.message;
|
|
139
|
+
if (Array.isArray(val) && val.length > 0) return String(val[0]);
|
|
140
|
+
return typeof val === "string" ? val : null;
|
|
141
|
+
},
|
|
142
|
+
() => {
|
|
143
|
+
const val = errorObj.error;
|
|
144
|
+
return typeof val === "string" ? val : null;
|
|
145
|
+
},
|
|
146
|
+
() => {
|
|
147
|
+
const val = errorObj.description;
|
|
148
|
+
return typeof val === "string" ? val : null;
|
|
149
|
+
},
|
|
150
|
+
() => {
|
|
151
|
+
const val = errorObj.detail;
|
|
152
|
+
return typeof val === "string" ? val : null;
|
|
153
|
+
},
|
|
109
154
|
// Other nested error messages
|
|
110
|
-
|
|
111
|
-
|
|
155
|
+
() => {
|
|
156
|
+
const val = getNestedProperty(errorObj, ["data", "error"]);
|
|
157
|
+
return typeof val === "string" ? val : null;
|
|
158
|
+
},
|
|
159
|
+
() => {
|
|
160
|
+
const val = getNestedProperty(errorObj, ["data", "message"]);
|
|
161
|
+
return typeof val === "string" ? val : null;
|
|
162
|
+
},
|
|
112
163
|
// Array format messages (fallback)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
164
|
+
() => {
|
|
165
|
+
const val = errorObj.error;
|
|
166
|
+
if (Array.isArray(val) && val.length > 0) return String(val[0]);
|
|
167
|
+
return null;
|
|
168
|
+
},
|
|
169
|
+
() => {
|
|
170
|
+
const val = errorObj.errors;
|
|
171
|
+
if (Array.isArray(val) && val.length > 0) return String(val[0]);
|
|
172
|
+
return null;
|
|
119
173
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
174
|
+
];
|
|
175
|
+
for (const checkPath of checkPaths) {
|
|
176
|
+
const result = checkPath();
|
|
177
|
+
if (result && result.trim().length > 0) {
|
|
178
|
+
return result.trim();
|
|
125
179
|
}
|
|
126
180
|
}
|
|
127
181
|
if (errorObj.validation && Array.isArray(errorObj.validation)) {
|
|
128
|
-
const validationErrors = errorObj.validation.map((v) =>
|
|
182
|
+
const validationErrors = errorObj.validation.map((v) => {
|
|
183
|
+
if (v && typeof v === "object") {
|
|
184
|
+
const vObj = v;
|
|
185
|
+
return vObj.message || vObj.error || String(v);
|
|
186
|
+
}
|
|
187
|
+
return String(v);
|
|
188
|
+
}).filter(Boolean).join(", ");
|
|
129
189
|
if (validationErrors) {
|
|
130
190
|
return `Validation error: ${validationErrors}`;
|
|
131
191
|
}
|
|
132
192
|
}
|
|
133
|
-
if (errorObj.statusCode && errorObj.statusText) {
|
|
193
|
+
if (typeof errorObj.statusCode === "number" && typeof errorObj.statusText === "string") {
|
|
134
194
|
return `${errorObj.statusCode}: ${errorObj.statusText}`;
|
|
135
195
|
}
|
|
136
196
|
const keys = Object.keys(errorObj);
|