@overmap-ai/core 1.0.49-fix-error-messaging.4 → 1.0.49-update-presigned-url-payload.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.
@@ -208,64 +208,18 @@ var __publicField = (obj, key, value) => {
208
208
  this.requestAttemptCounter[uuid2] = (this.requestAttemptCounter[uuid2] || 0) + 1;
209
209
  }
210
210
  }
211
- const UNKNOWN_ERROR_MESSAGE = "An unknown error occurred";
212
- const MAX_ERROR_MESSAGE_LENGTH = 500;
213
- const _SPECIAL_KEYS = ["non_field_errors", "detail"];
214
- function extractErrorMessage(errorRes, err) {
215
- let ret;
216
- if (errorRes == null ? void 0 : errorRes.body) {
217
- if (typeof errorRes.body === "object") {
218
- const responseBody = errorRes.body;
219
- if (typeof responseBody.error === "string") {
220
- ret = responseBody.error;
221
- } else if (typeof responseBody.message === "string") {
222
- ret = responseBody.message;
223
- } else if (responseBody.body) {
224
- try {
225
- ret = Object.entries(responseBody.body).map(([key, value]) => {
226
- if (typeof value === "string") {
227
- if (_SPECIAL_KEYS.includes(key))
228
- return value;
229
- return `${key}: ${value}`;
230
- }
231
- if (Array.isArray(value)) {
232
- if (_SPECIAL_KEYS.includes(key))
233
- return value.join("\n");
234
- return value.map((v) => `${key}: ${v}`).join("\n");
235
- }
236
- return `${key}: ${JSON.stringify(value)}`;
237
- }).join("\n");
238
- } catch (e) {
239
- console.error("Failed to extract error message from response body", e);
240
- }
241
- }
242
- } else if (typeof errorRes.body === "string") {
243
- ret = errorRes.body;
244
- }
245
- } else if (errorRes == null ? void 0 : errorRes.text) {
246
- ret = errorRes.text;
247
- } else if (err instanceof Error) {
248
- ret = err.message;
249
- }
250
- if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
251
- return UNKNOWN_ERROR_MESSAGE;
252
- }
253
- return ret;
254
- }
255
211
  class APIError extends Error {
256
- constructor(options) {
257
- super(UNKNOWN_ERROR_MESSAGE);
212
+ constructor(message, response, options) {
213
+ super(response == null ? void 0 : response.text);
258
214
  // NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
259
215
  __publicField(this, "status");
260
- __publicField(this, "response");
261
216
  __publicField(this, "message");
217
+ __publicField(this, "response");
262
218
  __publicField(this, "options");
263
- const { response, innerError } = options;
264
- this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
219
+ this.message = message;
265
220
  this.status = (response == null ? void 0 : response.status) ?? 0;
266
221
  this.response = response;
267
- options.discard = options.discard ?? false;
268
- this.options = options;
222
+ this.options = options ?? { discard: false };
269
223
  }
270
224
  }
271
225
  class DeferredPromise {
@@ -4214,6 +4168,35 @@ var __publicField = (obj, key, value) => {
4214
4168
  }
4215
4169
  return void 0;
4216
4170
  }
4171
+ function extractErrorMessage(errorRes, err) {
4172
+ if (errorRes == null ? void 0 : errorRes.body) {
4173
+ if (typeof errorRes.body === "object") {
4174
+ if (typeof errorRes.body.error === "string")
4175
+ return errorRes.body.error;
4176
+ if (typeof errorRes.body.message === "string")
4177
+ return errorRes.body.message;
4178
+ try {
4179
+ return Object.entries(errorRes.body).map(([key, value]) => {
4180
+ if (typeof value === "string") {
4181
+ return `${key}: ${value}`;
4182
+ }
4183
+ if (Array.isArray(value)) {
4184
+ return value.map((v) => `${key}: ${v}`).join("\n");
4185
+ }
4186
+ return `${key}: ${JSON.stringify(value)}`;
4187
+ }).join("\n");
4188
+ } catch (e) {
4189
+ console.error("Failed to extract error message from response body", e);
4190
+ }
4191
+ } else if (typeof errorRes.body === "string")
4192
+ return errorRes.body;
4193
+ } else if (errorRes == null ? void 0 : errorRes.text) {
4194
+ return errorRes.text;
4195
+ } else if (err instanceof Error) {
4196
+ return err.message;
4197
+ }
4198
+ return void 0;
4199
+ }
4217
4200
  async function performRequest(action, client) {
4218
4201
  async function checkToken() {
4219
4202
  if (client.auth.tokenIsExpiringSoon()) {
@@ -4316,29 +4299,19 @@ var __publicField = (obj, key, value) => {
4316
4299
  console.warn("No signed-in user to sign out.");
4317
4300
  }
4318
4301
  await client.auth.logout();
4319
- throw new APIError({
4320
- message: "You have been signed out due to inactivity.",
4321
- response: errorResponse,
4322
- discard: true,
4323
- innerError: error2
4324
- });
4325
- }
4326
- if (state.authReducer.isLoggedIn) {
4327
- console.debug("Forbidden; renewing tokens and retrying.");
4328
- await client.auth.renewTokens();
4329
- console.debug("Successfully renewed tokens; retrying request.");
4330
- return requestToSend.query(queryParams);
4331
- } else {
4332
- console.debug("Forbidden; user is not logged in.");
4333
- throw new APIError({
4334
- message: "Incorrect username or password.",
4335
- response: errorResponse,
4336
- discard: true,
4337
- innerError: error2
4302
+ throw new APIError("You have been signed out due to inactivity.", errorResponse, {
4303
+ discard: true
4338
4304
  });
4339
4305
  }
4306
+ console.debug("Forbidden; renewing tokens and retrying.");
4307
+ await client.auth.renewTokens();
4308
+ console.debug("Successfully renewed tokens; retrying request.");
4309
+ return requestToSend.query(queryParams);
4340
4310
  }
4341
- throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
4311
+ const apiErrorMessage = extractErrorMessage(errorResponse, error2) || "An unexpected error occurred.";
4312
+ throw new APIError(apiErrorMessage, errorResponse, {
4313
+ discard: discardStatuses.includes(status)
4314
+ });
4342
4315
  }
4343
4316
  }
4344
4317
  class MiddlewareChainerPrivate {
@@ -4549,29 +4522,18 @@ var __publicField = (obj, key, value) => {
4549
4522
  if (response) {
4550
4523
  promise.resolve(response.body);
4551
4524
  } else {
4552
- const error2 = new APIError({
4553
- message: "Could not get a response from the server.",
4525
+ const error2 = new APIError(
4526
+ "Could not get a response from the server.",
4554
4527
  response,
4555
- discard: true
4556
- });
4528
+ {
4529
+ discard: true
4530
+ }
4531
+ );
4557
4532
  promise.reject(error2);
4558
4533
  }
4559
4534
  };
4560
4535
  const errorHandler = (error2) => {
4561
- if (error2 instanceof APIError) {
4562
- error2.options.discard = true;
4563
- } else {
4564
- console.error(
4565
- "Received an unexpected error while processing a request:",
4566
- error2,
4567
- "\nConverting error to APIError and discarding."
4568
- );
4569
- error2 = new APIError({
4570
- message: "An error occurred while processing the request.",
4571
- innerError: error2,
4572
- discard: true
4573
- });
4574
- }
4536
+ error2.options.discard = true;
4575
4537
  promise.reject(error2);
4576
4538
  };
4577
4539
  innerPromise.then(successOrUndefinedHandler, errorHandler);
@@ -5151,23 +5113,24 @@ var __publicField = (obj, key, value) => {
5151
5113
  */
5152
5114
  __publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
5153
5115
  const uuid$1 = uuid.v4();
5154
- const responsePromise = this.enqueueRequest({
5155
- uuid: uuid$1,
5156
- description: "Get token pair",
5157
- method: HttpMethod.POST,
5158
- url: "/api/token/",
5159
- payload: credentials,
5160
- isAuthNeeded: false,
5161
- checkAuth: false,
5162
- blockers: [],
5163
- blocks: []
5164
- }).then(parseTokens).catch((e) => {
5116
+ try {
5117
+ const responsePromise = this.enqueueRequest({
5118
+ uuid: uuid$1,
5119
+ description: "Get token pair",
5120
+ method: HttpMethod.POST,
5121
+ url: "/api/token/",
5122
+ payload: credentials,
5123
+ isAuthNeeded: false,
5124
+ blockers: [],
5125
+ blocks: []
5126
+ });
5127
+ return [responsePromise.then(parseTokens), uuid$1];
5128
+ } catch (e) {
5165
5129
  if (logoutOnFailure) {
5166
5130
  void this.logout().then();
5167
5131
  }
5168
5132
  throw e;
5169
- });
5170
- return [responsePromise, uuid$1];
5133
+ }
5171
5134
  });
5172
5135
  /**
5173
5136
  * Takes refresh token and gets a new token pair
@@ -5228,7 +5191,7 @@ var __publicField = (obj, key, value) => {
5228
5191
  timedOut = true;
5229
5192
  store.dispatch(markForDeletion(uuid$1));
5230
5193
  store.dispatch(markForDeletion(initialDataUuid));
5231
- reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
5194
+ reject(new Error(`Request timed out after ${timeout} seconds`));
5232
5195
  }, timeout * 1e3);
5233
5196
  });
5234
5197
  const successPromise = promise.then((tokens) => {
@@ -7197,7 +7160,8 @@ var __publicField = (obj, key, value) => {
7197
7160
  blockers: [],
7198
7161
  blocks: []
7199
7162
  });
7200
- store.dispatch(setOrganizationAccesses(result));
7163
+ const organizationAccesses = result;
7164
+ store.dispatch(setOrganizationAccesses(organizationAccesses));
7201
7165
  }
7202
7166
  }
7203
7167
  const cachedRequestPromises = {};
@@ -7226,7 +7190,12 @@ var __publicField = (obj, key, value) => {
7226
7190
  description: "Get S3 URL",
7227
7191
  method: HttpMethod.GET,
7228
7192
  url: "/authentication/files/presigned-upload-url/",
7229
- queryParams: { key, type: file.type },
7193
+ queryParams: {
7194
+ sha1: await hashFile(file),
7195
+ file_type: file.type,
7196
+ extension: file.name.split(".").pop(),
7197
+ size: file.size.toString()
7198
+ },
7230
7199
  blockers: [],
7231
7200
  blocks: [`s3-${key}`]
7232
7201
  });