@overmap-ai/core 1.0.48 → 1.0.49-fix-error-messaging.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/overmap-core.js +66 -49
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +66 -49
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/errors.d.ts +6 -3
- package/dist/sdk/services/CategoryService.d.ts +2 -2
- package/dist/sdk/services/ComponentStageCompletionService.d.ts +2 -2
- package/dist/sdk/services/WorkspaceService.d.ts +2 -2
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -217,18 +217,54 @@ class OutboxCoordinator {
|
|
|
217
217
|
this.requestAttemptCounter[uuid] = (this.requestAttemptCounter[uuid] || 0) + 1;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
function extractErrorMessage(errorRes, err) {
|
|
221
|
+
if (errorRes == null ? void 0 : errorRes.body) {
|
|
222
|
+
if (typeof errorRes.body === "object") {
|
|
223
|
+
if (typeof errorRes.body.error === "string")
|
|
224
|
+
return errorRes.body.error;
|
|
225
|
+
if (typeof errorRes.body.message === "string")
|
|
226
|
+
return errorRes.body.message;
|
|
227
|
+
try {
|
|
228
|
+
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
229
|
+
if (typeof value === "string") {
|
|
230
|
+
if (key === "non_field_errors")
|
|
231
|
+
return value;
|
|
232
|
+
return `${key}: ${value}`;
|
|
233
|
+
}
|
|
234
|
+
if (Array.isArray(value)) {
|
|
235
|
+
if (key === "non_field_errors")
|
|
236
|
+
return value.join("\n");
|
|
237
|
+
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
238
|
+
}
|
|
239
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
240
|
+
}).join("\n");
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error("Failed to extract error message from response body", e);
|
|
243
|
+
}
|
|
244
|
+
} else if (typeof errorRes.body === "string")
|
|
245
|
+
return errorRes.body;
|
|
246
|
+
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
247
|
+
return errorRes.text;
|
|
248
|
+
} else if (err instanceof Error) {
|
|
249
|
+
return err.message;
|
|
250
|
+
}
|
|
251
|
+
return void 0;
|
|
252
|
+
}
|
|
220
253
|
class APIError extends Error {
|
|
221
|
-
constructor(
|
|
222
|
-
|
|
254
|
+
constructor(options) {
|
|
255
|
+
const unknownMessage = "An unknown error occurred";
|
|
256
|
+
super(unknownMessage);
|
|
223
257
|
// NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
|
|
224
258
|
__publicField(this, "status");
|
|
225
|
-
__publicField(this, "message");
|
|
226
259
|
__publicField(this, "response");
|
|
260
|
+
__publicField(this, "message");
|
|
227
261
|
__publicField(this, "options");
|
|
228
|
-
|
|
262
|
+
const { response, innerError } = options;
|
|
263
|
+
this.message = options.message ?? extractErrorMessage(response, innerError) ?? unknownMessage;
|
|
229
264
|
this.status = (response == null ? void 0 : response.status) ?? 0;
|
|
230
265
|
this.response = response;
|
|
231
|
-
|
|
266
|
+
options.discard = options.discard ?? false;
|
|
267
|
+
this.options = options;
|
|
232
268
|
}
|
|
233
269
|
}
|
|
234
270
|
class DeferredPromise {
|
|
@@ -4177,35 +4213,6 @@ function extractResponseFromError(error2) {
|
|
|
4177
4213
|
}
|
|
4178
4214
|
return void 0;
|
|
4179
4215
|
}
|
|
4180
|
-
function extractErrorMessage(errorRes, err) {
|
|
4181
|
-
if (errorRes == null ? void 0 : errorRes.body) {
|
|
4182
|
-
if (typeof errorRes.body === "object") {
|
|
4183
|
-
if (typeof errorRes.body.error === "string")
|
|
4184
|
-
return errorRes.body.error;
|
|
4185
|
-
if (typeof errorRes.body.message === "string")
|
|
4186
|
-
return errorRes.body.message;
|
|
4187
|
-
try {
|
|
4188
|
-
return Object.entries(errorRes.body).map(([key, value]) => {
|
|
4189
|
-
if (typeof value === "string") {
|
|
4190
|
-
return `${key}: ${value}`;
|
|
4191
|
-
}
|
|
4192
|
-
if (Array.isArray(value)) {
|
|
4193
|
-
return value.map((v) => `${key}: ${v}`).join("\n");
|
|
4194
|
-
}
|
|
4195
|
-
return `${key}: ${JSON.stringify(value)}`;
|
|
4196
|
-
}).join("\n");
|
|
4197
|
-
} catch (e) {
|
|
4198
|
-
console.error("Failed to extract error message from response body", e);
|
|
4199
|
-
}
|
|
4200
|
-
} else if (typeof errorRes.body === "string")
|
|
4201
|
-
return errorRes.body;
|
|
4202
|
-
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
4203
|
-
return errorRes.text;
|
|
4204
|
-
} else if (err instanceof Error) {
|
|
4205
|
-
return err.message;
|
|
4206
|
-
}
|
|
4207
|
-
return void 0;
|
|
4208
|
-
}
|
|
4209
4216
|
async function performRequest(action, client) {
|
|
4210
4217
|
async function checkToken() {
|
|
4211
4218
|
if (client.auth.tokenIsExpiringSoon()) {
|
|
@@ -4308,8 +4315,11 @@ async function performRequest(action, client) {
|
|
|
4308
4315
|
console.warn("No signed-in user to sign out.");
|
|
4309
4316
|
}
|
|
4310
4317
|
await client.auth.logout();
|
|
4311
|
-
throw new APIError(
|
|
4312
|
-
|
|
4318
|
+
throw new APIError({
|
|
4319
|
+
message: "You have been signed out due to inactivity.",
|
|
4320
|
+
response: errorResponse,
|
|
4321
|
+
discard: true,
|
|
4322
|
+
innerError: error2
|
|
4313
4323
|
});
|
|
4314
4324
|
}
|
|
4315
4325
|
console.debug("Forbidden; renewing tokens and retrying.");
|
|
@@ -4317,10 +4327,7 @@ async function performRequest(action, client) {
|
|
|
4317
4327
|
console.debug("Successfully renewed tokens; retrying request.");
|
|
4318
4328
|
return requestToSend.query(queryParams);
|
|
4319
4329
|
}
|
|
4320
|
-
|
|
4321
|
-
throw new APIError(apiErrorMessage, errorResponse, {
|
|
4322
|
-
discard: discardStatuses.includes(status)
|
|
4323
|
-
});
|
|
4330
|
+
throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
|
|
4324
4331
|
}
|
|
4325
4332
|
}
|
|
4326
4333
|
class MiddlewareChainerPrivate {
|
|
@@ -4531,18 +4538,29 @@ class BaseApiService {
|
|
|
4531
4538
|
if (response) {
|
|
4532
4539
|
promise.resolve(response.body);
|
|
4533
4540
|
} else {
|
|
4534
|
-
const error2 = new APIError(
|
|
4535
|
-
"Could not get a response from the server.",
|
|
4541
|
+
const error2 = new APIError({
|
|
4542
|
+
message: "Could not get a response from the server.",
|
|
4536
4543
|
response,
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
}
|
|
4540
|
-
);
|
|
4544
|
+
discard: true
|
|
4545
|
+
});
|
|
4541
4546
|
promise.reject(error2);
|
|
4542
4547
|
}
|
|
4543
4548
|
};
|
|
4544
4549
|
const errorHandler = (error2) => {
|
|
4545
|
-
error2
|
|
4550
|
+
if (error2 instanceof APIError) {
|
|
4551
|
+
error2.options.discard = true;
|
|
4552
|
+
} else {
|
|
4553
|
+
console.error(
|
|
4554
|
+
"Received an unexpected error while processing a request:",
|
|
4555
|
+
error2,
|
|
4556
|
+
"\nConverting error to APIError and discarding."
|
|
4557
|
+
);
|
|
4558
|
+
error2 = new APIError({
|
|
4559
|
+
message: "An error occurred while processing the request.",
|
|
4560
|
+
innerError: error2,
|
|
4561
|
+
discard: true
|
|
4562
|
+
});
|
|
4563
|
+
}
|
|
4546
4564
|
promise.reject(error2);
|
|
4547
4565
|
};
|
|
4548
4566
|
innerPromise.then(successOrUndefinedHandler, errorHandler);
|
|
@@ -7169,8 +7187,7 @@ class OrganizationAccessService extends BaseApiService {
|
|
|
7169
7187
|
blockers: [],
|
|
7170
7188
|
blocks: []
|
|
7171
7189
|
});
|
|
7172
|
-
|
|
7173
|
-
store.dispatch(setOrganizationAccesses(organizationAccesses));
|
|
7190
|
+
store.dispatch(setOrganizationAccesses(result));
|
|
7174
7191
|
}
|
|
7175
7192
|
}
|
|
7176
7193
|
const cachedRequestPromises = {};
|