@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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @overmap-ai/core
2
-
3
- The `core` package contains core functionality for the Overmap platform. It is a peer dependency of all other overmap
4
- packages.
1
+ # @overmap-ai/core
2
+
3
+ The `core` package contains core functionality for the Overmap platform. It is a peer dependency of all other overmap
4
+ packages.
@@ -217,64 +217,18 @@ class OutboxCoordinator {
217
217
  this.requestAttemptCounter[uuid] = (this.requestAttemptCounter[uuid] || 0) + 1;
218
218
  }
219
219
  }
220
- const UNKNOWN_ERROR_MESSAGE = "An unknown error occurred";
221
- const MAX_ERROR_MESSAGE_LENGTH = 500;
222
- const _SPECIAL_KEYS = ["non_field_errors", "detail"];
223
- function extractErrorMessage(errorRes, err) {
224
- let ret;
225
- if (errorRes == null ? void 0 : errorRes.body) {
226
- if (typeof errorRes.body === "object") {
227
- const responseBody = errorRes.body;
228
- if (typeof responseBody.error === "string") {
229
- ret = responseBody.error;
230
- } else if (typeof responseBody.message === "string") {
231
- ret = responseBody.message;
232
- } else if (responseBody.body) {
233
- try {
234
- ret = Object.entries(responseBody.body).map(([key, value]) => {
235
- if (typeof value === "string") {
236
- if (_SPECIAL_KEYS.includes(key))
237
- return value;
238
- return `${key}: ${value}`;
239
- }
240
- if (Array.isArray(value)) {
241
- if (_SPECIAL_KEYS.includes(key))
242
- return value.join("\n");
243
- return value.map((v) => `${key}: ${v}`).join("\n");
244
- }
245
- return `${key}: ${JSON.stringify(value)}`;
246
- }).join("\n");
247
- } catch (e) {
248
- console.error("Failed to extract error message from response body", e);
249
- }
250
- }
251
- } else if (typeof errorRes.body === "string") {
252
- ret = errorRes.body;
253
- }
254
- } else if (errorRes == null ? void 0 : errorRes.text) {
255
- ret = errorRes.text;
256
- } else if (err instanceof Error) {
257
- ret = err.message;
258
- }
259
- if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
260
- return UNKNOWN_ERROR_MESSAGE;
261
- }
262
- return ret;
263
- }
264
220
  class APIError extends Error {
265
- constructor(options) {
266
- super(UNKNOWN_ERROR_MESSAGE);
221
+ constructor(message, response, options) {
222
+ super(response == null ? void 0 : response.text);
267
223
  // NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
268
224
  __publicField(this, "status");
269
- __publicField(this, "response");
270
225
  __publicField(this, "message");
226
+ __publicField(this, "response");
271
227
  __publicField(this, "options");
272
- const { response, innerError } = options;
273
- this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
228
+ this.message = message;
274
229
  this.status = (response == null ? void 0 : response.status) ?? 0;
275
230
  this.response = response;
276
- options.discard = options.discard ?? false;
277
- this.options = options;
231
+ this.options = options ?? { discard: false };
278
232
  }
279
233
  }
280
234
  class DeferredPromise {
@@ -4223,6 +4177,35 @@ function extractResponseFromError(error2) {
4223
4177
  }
4224
4178
  return void 0;
4225
4179
  }
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
+ }
4226
4209
  async function performRequest(action, client) {
4227
4210
  async function checkToken() {
4228
4211
  if (client.auth.tokenIsExpiringSoon()) {
@@ -4325,29 +4308,19 @@ async function performRequest(action, client) {
4325
4308
  console.warn("No signed-in user to sign out.");
4326
4309
  }
4327
4310
  await client.auth.logout();
4328
- throw new APIError({
4329
- message: "You have been signed out due to inactivity.",
4330
- response: errorResponse,
4331
- discard: true,
4332
- innerError: error2
4333
- });
4334
- }
4335
- if (state.authReducer.isLoggedIn) {
4336
- console.debug("Forbidden; renewing tokens and retrying.");
4337
- await client.auth.renewTokens();
4338
- console.debug("Successfully renewed tokens; retrying request.");
4339
- return requestToSend.query(queryParams);
4340
- } else {
4341
- console.debug("Forbidden; user is not logged in.");
4342
- throw new APIError({
4343
- message: "Incorrect username or password.",
4344
- response: errorResponse,
4345
- discard: true,
4346
- innerError: error2
4311
+ throw new APIError("You have been signed out due to inactivity.", errorResponse, {
4312
+ discard: true
4347
4313
  });
4348
4314
  }
4315
+ console.debug("Forbidden; renewing tokens and retrying.");
4316
+ await client.auth.renewTokens();
4317
+ console.debug("Successfully renewed tokens; retrying request.");
4318
+ return requestToSend.query(queryParams);
4349
4319
  }
4350
- throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
4320
+ const apiErrorMessage = extractErrorMessage(errorResponse, error2) || "An unexpected error occurred.";
4321
+ throw new APIError(apiErrorMessage, errorResponse, {
4322
+ discard: discardStatuses.includes(status)
4323
+ });
4351
4324
  }
4352
4325
  }
4353
4326
  class MiddlewareChainerPrivate {
@@ -4558,29 +4531,18 @@ class BaseApiService {
4558
4531
  if (response) {
4559
4532
  promise.resolve(response.body);
4560
4533
  } else {
4561
- const error2 = new APIError({
4562
- message: "Could not get a response from the server.",
4534
+ const error2 = new APIError(
4535
+ "Could not get a response from the server.",
4563
4536
  response,
4564
- discard: true
4565
- });
4537
+ {
4538
+ discard: true
4539
+ }
4540
+ );
4566
4541
  promise.reject(error2);
4567
4542
  }
4568
4543
  };
4569
4544
  const errorHandler = (error2) => {
4570
- if (error2 instanceof APIError) {
4571
- error2.options.discard = true;
4572
- } else {
4573
- console.error(
4574
- "Received an unexpected error while processing a request:",
4575
- error2,
4576
- "\nConverting error to APIError and discarding."
4577
- );
4578
- error2 = new APIError({
4579
- message: "An error occurred while processing the request.",
4580
- innerError: error2,
4581
- discard: true
4582
- });
4583
- }
4545
+ error2.options.discard = true;
4584
4546
  promise.reject(error2);
4585
4547
  };
4586
4548
  innerPromise.then(successOrUndefinedHandler, errorHandler);
@@ -5160,23 +5122,24 @@ class AuthService extends BaseApiService {
5160
5122
  */
5161
5123
  __publicField(this, "_getTokenPair", (credentials, logoutOnFailure = true) => {
5162
5124
  const uuid = v4();
5163
- const responsePromise = this.enqueueRequest({
5164
- uuid,
5165
- description: "Get token pair",
5166
- method: HttpMethod.POST,
5167
- url: "/api/token/",
5168
- payload: credentials,
5169
- isAuthNeeded: false,
5170
- checkAuth: false,
5171
- blockers: [],
5172
- blocks: []
5173
- }).then(parseTokens).catch((e) => {
5125
+ try {
5126
+ const responsePromise = this.enqueueRequest({
5127
+ uuid,
5128
+ description: "Get token pair",
5129
+ method: HttpMethod.POST,
5130
+ url: "/api/token/",
5131
+ payload: credentials,
5132
+ isAuthNeeded: false,
5133
+ blockers: [],
5134
+ blocks: []
5135
+ });
5136
+ return [responsePromise.then(parseTokens), uuid];
5137
+ } catch (e) {
5174
5138
  if (logoutOnFailure) {
5175
5139
  void this.logout().then();
5176
5140
  }
5177
5141
  throw e;
5178
- });
5179
- return [responsePromise, uuid];
5142
+ }
5180
5143
  });
5181
5144
  /**
5182
5145
  * Takes refresh token and gets a new token pair
@@ -5237,7 +5200,7 @@ class AuthService extends BaseApiService {
5237
5200
  timedOut = true;
5238
5201
  store.dispatch(markForDeletion(uuid));
5239
5202
  store.dispatch(markForDeletion(initialDataUuid));
5240
- reject(new APIError({ message: `Request timed out after ${timeout} seconds` }));
5203
+ reject(new Error(`Request timed out after ${timeout} seconds`));
5241
5204
  }, timeout * 1e3);
5242
5205
  });
5243
5206
  const successPromise = promise.then((tokens) => {
@@ -7206,7 +7169,8 @@ class OrganizationAccessService extends BaseApiService {
7206
7169
  blockers: [],
7207
7170
  blocks: []
7208
7171
  });
7209
- store.dispatch(setOrganizationAccesses(result));
7172
+ const organizationAccesses = result;
7173
+ store.dispatch(setOrganizationAccesses(organizationAccesses));
7210
7174
  }
7211
7175
  }
7212
7176
  const cachedRequestPromises = {};
@@ -7235,7 +7199,12 @@ class FileService extends BaseApiService {
7235
7199
  description: "Get S3 URL",
7236
7200
  method: HttpMethod.GET,
7237
7201
  url: "/authentication/files/presigned-upload-url/",
7238
- queryParams: { key, type: file.type },
7202
+ queryParams: {
7203
+ sha1: await hashFile(file),
7204
+ file_type: file.type,
7205
+ extension: file.name.split(".").pop(),
7206
+ size: file.size.toString()
7207
+ },
7239
7208
  blockers: [],
7240
7209
  blocks: [`s3-${key}`]
7241
7210
  });