@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.
- package/dist/overmap-core.js +53 -32
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +53 -32
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/store/store.d.ts +1 -1
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
251
|
+
} else if (typeof errorRes.body === "string") {
|
|
252
|
+
ret = errorRes.body;
|
|
253
|
+
}
|
|
246
254
|
} else if (errorRes == null ? void 0 : errorRes.text) {
|
|
247
|
-
|
|
255
|
+
ret = errorRes.text;
|
|
248
256
|
} else if (err instanceof Error) {
|
|
249
|
-
|
|
257
|
+
ret = err.message;
|
|
250
258
|
}
|
|
251
|
-
|
|
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
|
-
|
|
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) ??
|
|
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
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
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) => {
|