@overmap-ai/core 1.0.49-fix-error-messaging.2 → 1.0.49-fix-error-messaging.4

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,50 +217,60 @@ 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"];
220
223
  function extractErrorMessage(errorRes, err) {
224
+ let ret;
221
225
  if (errorRes == null ? void 0 : errorRes.body) {
222
226
  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);
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
+ }
243
250
  }
244
- } else if (typeof errorRes.body === "string")
245
- return errorRes.body;
251
+ } else if (typeof errorRes.body === "string") {
252
+ ret = errorRes.body;
253
+ }
246
254
  } else if (errorRes == null ? void 0 : errorRes.text) {
247
- return errorRes.text;
255
+ ret = errorRes.text;
248
256
  } else if (err instanceof Error) {
249
- return err.message;
257
+ ret = err.message;
250
258
  }
251
- return void 0;
259
+ if (!ret || ret.length > MAX_ERROR_MESSAGE_LENGTH) {
260
+ return UNKNOWN_ERROR_MESSAGE;
261
+ }
262
+ return ret;
252
263
  }
253
264
  class APIError extends Error {
254
265
  constructor(options) {
255
- const unknownMessage = "An unknown error occurred";
256
- super(unknownMessage);
266
+ super(UNKNOWN_ERROR_MESSAGE);
257
267
  // NOTE: Needs to conform to NetworkError in @redux-offline/redux-offline, which has `status` and `response`.
258
268
  __publicField(this, "status");
259
269
  __publicField(this, "response");
260
270
  __publicField(this, "message");
261
271
  __publicField(this, "options");
262
272
  const { response, innerError } = options;
263
- this.message = options.message ?? extractErrorMessage(response, innerError) ?? unknownMessage;
273
+ this.message = options.message ?? extractErrorMessage(response, innerError) ?? UNKNOWN_ERROR_MESSAGE;
264
274
  this.status = (response == null ? void 0 : response.status) ?? 0;
265
275
  this.response = response;
266
276
  options.discard = options.discard ?? false;
@@ -4322,10 +4332,20 @@ async function performRequest(action, client) {
4322
4332
  innerError: error2
4323
4333
  });
4324
4334
  }
4325
- console.debug("Forbidden; renewing tokens and retrying.");
4326
- await client.auth.renewTokens();
4327
- console.debug("Successfully renewed tokens; retrying request.");
4328
- return requestToSend.query(queryParams);
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
4347
+ });
4348
+ }
4329
4349
  }
4330
4350
  throw new APIError({ response: errorResponse, innerError: error2, discard: discardStatuses.includes(status) });
4331
4351
  }
@@ -5147,6 +5167,7 @@ class AuthService extends BaseApiService {
5147
5167
  url: "/api/token/",
5148
5168
  payload: credentials,
5149
5169
  isAuthNeeded: false,
5170
+ checkAuth: false,
5150
5171
  blockers: [],
5151
5172
  blocks: []
5152
5173
  }).then(parseTokens).catch((e) => {