@overmap-ai/core 1.0.25-fix-api-error-messages.2 → 1.0.25-fix-api-error-messages.3

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.
@@ -3316,7 +3316,6 @@ const defaultStore = configureStore({
3316
3316
  }
3317
3317
  });
3318
3318
  async function performRequest(action, client) {
3319
- var _a2;
3320
3319
  async function checkToken() {
3321
3320
  if (client.auth.tokenIsExpiringSoon()) {
3322
3321
  await client.auth.renewTokens();
@@ -3411,9 +3410,13 @@ async function performRequest(action, client) {
3411
3410
  return await requestToSend.query(queryParams);
3412
3411
  } catch (error) {
3413
3412
  console.debug("TYPE OF ERROR:", typeof error, error instanceof Error, error instanceof Response);
3413
+ if (error instanceof Error) {
3414
+ console.error(error.message);
3415
+ }
3414
3416
  console.error(error);
3415
3417
  const originalError = error;
3416
- if (originalError.status === 401) {
3418
+ const status = originalError["status"];
3419
+ if (status === 401) {
3417
3420
  console.debug("Forbidden; renewing tokens and retrying.");
3418
3421
  try {
3419
3422
  await client.auth.renewTokens();
@@ -3428,27 +3431,23 @@ async function performRequest(action, client) {
3428
3431
  } else {
3429
3432
  console.warn("No signed-in user to sign out.");
3430
3433
  }
3431
- throw new APIError("You have been signed out due to inactivity.", originalError, { discard: true });
3434
+ throw new APIError("You have been signed out due to inactivity.", originalError, {
3435
+ discard: true
3436
+ });
3432
3437
  }
3433
3438
  }
3434
- const apiErrorMessage = ((_a2 = originalError.body) == null ? void 0 : _a2.error) ?? originalError.text ?? originalError.error;
3435
- console.log(
3436
- "API error:",
3437
- originalError,
3438
- originalError.error,
3439
- originalError.text,
3440
- originalError.body,
3441
- originalError.status
3442
- );
3439
+ const members = ["message", "text", "body", "error"];
3440
+ const apiErrorMessage = members.map((member) => originalError[member]).find((member) => member !== void 0);
3443
3441
  throw new APIError(
3444
3442
  typeof apiErrorMessage === "string" ? apiErrorMessage : (
3445
3443
  // TODO: Error codes for all APIErrors.
3446
3444
  // TODO: Constant for all messages.
3447
- originalError.text || "An unexpected error occurred."
3445
+ "An unexpected error occurred."
3448
3446
  ),
3447
+ // TODO: Update the type in APIError to accept Error as well, or figure out when it's this or that.
3449
3448
  originalError,
3450
3449
  {
3451
- discard: discardStatuses.includes(originalError.status)
3450
+ discard: discardStatuses.includes(status)
3452
3451
  }
3453
3452
  );
3454
3453
  }