@overmap-ai/core 1.0.49-fix-error-messaging.3 → 1.0.49-fix-error-messaging.4
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/overmap-core.js +38 -28
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +38 -28
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -217,50 +217,60 @@ class OutboxCoordinator {
|
|
|
217
217
|
this.requestAttemptCounter[uuid] = (this.requestAttemptCounter[uuid] || 0) + 1;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
const UNKNOWN_ERROR_MESSAGE = "An unknown error occurred";
|
|
221
|
+
const MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
222
|
+
const _SPECIAL_KEYS = ["non_field_errors", "detail"];
|
|
220
223
|
function extractErrorMessage(errorRes, err) {
|
|
224
|
+
let ret;
|
|
221
225
|
if (errorRes == null ? void 0 : errorRes.body) {
|
|
222
226
|
if (typeof errorRes.body === "object") {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
227
|
+
const responseBody = errorRes.body;
|
|
228
|
+
if (typeof responseBody.error === "string") {
|
|
229
|
+
ret = responseBody.error;
|
|
230
|
+
} else if (typeof responseBody.message === "string") {
|
|
231
|
+
ret = responseBody.message;
|
|
232
|
+
} else if (responseBody.body) {
|
|
233
|
+
try {
|
|
234
|
+
ret = Object.entries(responseBody.body).map(([key, value]) => {
|
|
235
|
+
if (typeof value === "string") {
|
|
236
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
237
|
+
return value;
|
|
238
|
+
return `${key}: ${value}`;
|
|
239
|
+
}
|
|
240
|
+
if (Array.isArray(value)) {
|
|
241
|
+
if (_SPECIAL_KEYS.includes(key))
|
|
242
|
+
return value.join("\n");
|
|
243
|
+
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
244
|
+
}
|
|
245
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
246
|
+
}).join("\n");
|
|
247
|
+
} catch (e) {
|
|
248
|
+
console.error("Failed to extract error message from response body", e);
|
|
249
|
+
}
|
|
243
250
|
}
|
|
244
|
-
} else if (typeof errorRes.body === "string")
|
|
245
|
-
|
|
251
|
+
} else if (typeof errorRes.body === "string") {
|
|
252
|
+
ret = errorRes.body;
|
|
253
|
+
}
|
|
246
254
|
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
247
|
-
|
|
255
|
+
ret = errorRes.text;
|
|
248
256
|
} else if (err instanceof Error) {
|
|
249
|
-
|
|
257
|
+
ret = err.message;
|
|
250
258
|
}
|
|
251
|
-
|
|
259
|
+
if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
|
|
260
|
+
return UNKNOWN_ERROR_MESSAGE;
|
|
261
|
+
}
|
|
262
|
+
return ret;
|
|
252
263
|
}
|
|
253
264
|
class APIError extends Error {
|
|
254
265
|
constructor(options) {
|
|
255
|
-
|
|
256
|
-
super(unknownMessage);
|
|
266
|
+
super(UNKNOWN_ERROR_MESSAGE);
|
|
257
267
|
// NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
|
|
258
268
|
__publicField(this, "status");
|
|
259
269
|
__publicField(this, "response");
|
|
260
270
|
__publicField(this, "message");
|
|
261
271
|
__publicField(this, "options");
|
|
262
272
|
const { response, innerError } = options;
|
|
263
|
-
this.message = options.message ?? extractErrorMessage(response, innerError) ??
|
|
273
|
+
this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
|
|
264
274
|
this.status = (response == null ? void 0 : response.status) ?? 0;
|
|
265
275
|
this.response = response;
|
|
266
276
|
options.discard = options.discard ?? false;
|