@overmap-ai/core 1.0.48 → 1.0.49-fix-error-messaging.0

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.
@@ -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(message, response, options) {
222
- super(response == null ? void 0 : response.text);
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
- this.message = message;
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
- this.options = options ?? { discard: false };
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("You have been signed out due to inactivity.", errorResponse, {
4312
- discard: true
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
- const apiErrorMessage = extractErrorMessage(errorResponse, error2) || "An unexpected error occurred.";
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,13 +4538,11 @@ 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
- discard: true
4539
- }
4540
- );
4544
+ discard: true
4545
+ });
4541
4546
  promise.reject(error2);
4542
4547
  }
4543
4548
  };
@@ -7169,8 +7174,7 @@ class OrganizationAccessService extends BaseApiService {
7169
7174
  blockers: [],
7170
7175
  blocks: []
7171
7176
  });
7172
- const organizationAccesses = result;
7173
- store.dispatch(setOrganizationAccesses(organizationAccesses));
7177
+ store.dispatch(setOrganizationAccesses(result));
7174
7178
  }
7175
7179
  }
7176
7180
  const cachedRequestPromises = {};