@overmap-ai/core 1.0.35-debug-file.1 → 1.0.35-fix-token-refresh-loop.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.
@@ -3465,6 +3465,19 @@ function extractErrorMessage(errorRes, err) {
3465
3465
  return errorRes.body.error;
3466
3466
  if (typeof errorRes.body.message === "string")
3467
3467
  return errorRes.body.message;
3468
+ try {
3469
+ return Object.entries(errorRes.body).map(([key, value]) => {
3470
+ if (typeof value === "string") {
3471
+ return `${key}: ${value}`;
3472
+ }
3473
+ if (Array.isArray(value)) {
3474
+ return value.map((v) => `${key}: ${v}`).join("\n");
3475
+ }
3476
+ return `${key}: ${JSON.stringify(value)}`;
3477
+ }).join("\n");
3478
+ } catch (e) {
3479
+ console.error("Failed to extract error message from response body", e);
3480
+ }
3468
3481
  } else if (typeof errorRes.body === "string")
3469
3482
  return errorRes.body;
3470
3483
  } else if (errorRes == null ? void 0 : errorRes.text) {
@@ -3883,7 +3896,6 @@ class AttachmentService extends BaseApiService {
3883
3896
  throw new Error(`Attachment ${attachmentId} not found`);
3884
3897
  let oldFile = void 0;
3885
3898
  const newSha1 = await hashFile(newFile);
3886
- console.log(attachment, newFile);
3887
3899
  const performRequest2 = async () => {
3888
3900
  oldFile = await this.client.files.fetchCache(attachment.file_sha1);
3889
3901
  if (!oldFile) {
@@ -3898,13 +3910,12 @@ class AttachmentService extends BaseApiService {
3898
3910
  store.dispatch(updateAttachment(attachment));
3899
3911
  throw e;
3900
3912
  });
3901
- console.log(fileProps);
3902
3913
  const promise2 = this.enqueueRequest({
3903
3914
  description: "Edit attachment",
3904
3915
  method: HttpMethod.PATCH,
3905
3916
  url: `/attachments/${attachment.offline_id}/`,
3906
3917
  isResponseBlob: false,
3907
- payload: { ...fileProps, file_type: newFile.type },
3918
+ payload: fileProps,
3908
3919
  blockers: [attachmentId, newSha1],
3909
3920
  blocks: [attachmentId, newSha1]
3910
3921
  });
@@ -3930,7 +3941,6 @@ class AttachmentService extends BaseApiService {
3930
3941
  file_sha1: newSha1,
3931
3942
  file: URL.createObjectURL(newFile)
3932
3943
  };
3933
- console.log(offlineAttachment);
3934
3944
  const promise = performRequest2();
3935
3945
  return [offlineAttachment, promise];
3936
3946
  }
@@ -4008,7 +4018,7 @@ class AuthService extends BaseApiService {
4008
4018
  * @returns {Promise<TokenPair>} The new access and refresh tokens
4009
4019
  */
4010
4020
  __publicField(this, "_getRenewedTokens", async (refreshToken) => {
4011
- const response = await this.enqueueRequest({
4021
+ const promise = this.enqueueRequest({
4012
4022
  description: "Get renewed tokens",
4013
4023
  method: HttpMethod.POST,
4014
4024
  url: "/api/token/refresh/",
@@ -4021,6 +4031,14 @@ class AuthService extends BaseApiService {
4021
4031
  // Don't wait for other requests to finish, or we might end up in a deadlock.
4022
4032
  immediate: true
4023
4033
  });
4034
+ let response = void 0;
4035
+ try {
4036
+ response = await promise;
4037
+ } catch (e) {
4038
+ await this.logout();
4039
+ }
4040
+ if (!response)
4041
+ throw new Error("No response");
4024
4042
  if (!response.access)
4025
4043
  throw new Error("Missing access token");
4026
4044
  if (!response.refresh)