@xh/hoist 75.0.0-SNAPSHOT.1752777363110 → 75.0.0-SNAPSHOT.1752854198386
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HoistException } from '../';
|
|
1
|
+
import { HoistException, PlainObject } from '../';
|
|
2
2
|
export interface ExceptionHandlerOptions {
|
|
3
3
|
/** Text (ideally user-friendly) describing the error. */
|
|
4
4
|
message?: string;
|
|
@@ -113,8 +113,13 @@ export declare class ExceptionHandler {
|
|
|
113
113
|
*/
|
|
114
114
|
logOnServerAsync(options: ExceptionHandlerLoggingOptions): Promise<boolean>;
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
116
|
+
* Sanitize an exception for submission to server. This method will avoid circular references
|
|
117
|
+
* trim the depth of the object, and redact sensitive info (e.g. passwords).
|
|
118
|
+
*/
|
|
119
|
+
sanitizeException(exception: HoistException): PlainObject;
|
|
120
|
+
/**
|
|
121
|
+
* Serialize an error object safely for user display. This method will avoid circular
|
|
122
|
+
* references, trim the depth of the object, and redact sensitive info (e.g. passwords).
|
|
118
123
|
*/
|
|
119
124
|
stringifyErrorSafely(exception: HoistException): string;
|
|
120
125
|
private parseArgs;
|
|
@@ -122,6 +127,5 @@ export declare class ExceptionHandler {
|
|
|
122
127
|
private logException;
|
|
123
128
|
private parseOptions;
|
|
124
129
|
private sessionMismatch;
|
|
125
|
-
private cleanStack;
|
|
126
130
|
private cloneAndTrim;
|
|
127
131
|
}
|
|
@@ -210,7 +210,7 @@ export class Exception {
|
|
|
210
210
|
|
|
211
211
|
private static createInternal(attributes: PlainObject, baseError?: Error) {
|
|
212
212
|
const {message, ...rest} = attributes;
|
|
213
|
-
|
|
213
|
+
const ret = Object.assign(
|
|
214
214
|
baseError ?? new Error(message),
|
|
215
215
|
{
|
|
216
216
|
isRoutine: false,
|
|
@@ -218,6 +218,11 @@ export class Exception {
|
|
|
218
218
|
},
|
|
219
219
|
rest
|
|
220
220
|
) as HoistException;
|
|
221
|
+
|
|
222
|
+
// statuses of 0, 4XX, 5XX are server errors, so stack irrelevant and potentially misleading
|
|
223
|
+
if (ret.stack == null || /^[045]/.test(ret.httpStatus)) delete ret.stack;
|
|
224
|
+
|
|
225
|
+
return ret;
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
|
|
@@ -185,8 +185,7 @@ export class ExceptionHandler {
|
|
|
185
185
|
async logOnServerAsync(options: ExceptionHandlerLoggingOptions): Promise<boolean> {
|
|
186
186
|
const {exception, userAlerted, userMessage} = options;
|
|
187
187
|
try {
|
|
188
|
-
const
|
|
189
|
-
username = XH.getUsername();
|
|
188
|
+
const username = XH.getUsername();
|
|
190
189
|
|
|
191
190
|
if (!username) {
|
|
192
191
|
logWarn('Error report cannot be submitted to UI server - user unknown', this);
|
|
@@ -194,7 +193,7 @@ export class ExceptionHandler {
|
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
const data: PlainObject = {
|
|
197
|
-
error:
|
|
196
|
+
error: this.sanitizeException(exception),
|
|
198
197
|
userAlerted
|
|
199
198
|
};
|
|
200
199
|
if (userMessage) data.userMessage = stripTags(userMessage);
|
|
@@ -216,8 +215,16 @@ export class ExceptionHandler {
|
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
218
|
+
* Sanitize an exception for submission to server. This method will avoid circular references
|
|
219
|
+
* trim the depth of the object, and redact sensitive info (e.g. passwords).
|
|
220
|
+
*/
|
|
221
|
+
sanitizeException(exception: HoistException): PlainObject {
|
|
222
|
+
return JSON.parse(this.stringifyErrorSafely(exception));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Serialize an error object safely for user display. This method will avoid circular
|
|
227
|
+
* references, trim the depth of the object, and redact sensitive info (e.g. passwords).
|
|
221
228
|
*/
|
|
222
229
|
stringifyErrorSafely(exception: HoistException): string {
|
|
223
230
|
try {
|
|
@@ -287,8 +294,6 @@ export class ExceptionHandler {
|
|
|
287
294
|
this.hideParams(e, opts);
|
|
288
295
|
}
|
|
289
296
|
|
|
290
|
-
this.cleanStack(e);
|
|
291
|
-
|
|
292
297
|
return {e, opts};
|
|
293
298
|
}
|
|
294
299
|
|
|
@@ -342,12 +347,6 @@ export class ExceptionHandler {
|
|
|
342
347
|
return e.name === 'SessionMismatchException';
|
|
343
348
|
}
|
|
344
349
|
|
|
345
|
-
private cleanStack(e: HoistException) {
|
|
346
|
-
// statuses of 0, 4XX, 5XX are server errors, so the javascript stack
|
|
347
|
-
// is irrelevant and potentially misleading
|
|
348
|
-
if (/^[045]/.test(e.httpStatus)) delete e.stack;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
350
|
private cloneAndTrim(obj, depth = 5) {
|
|
352
351
|
// Create a depth-constrained, deep copy of an object for safe-use in stringify
|
|
353
352
|
// - Skip private _XXXX properties.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist",
|
|
3
|
-
"version": "75.0.0-SNAPSHOT.
|
|
3
|
+
"version": "75.0.0-SNAPSHOT.1752854198386",
|
|
4
4
|
"description": "Hoist add-on for building and deploying React Applications.",
|
|
5
5
|
"repository": "github:xh/hoist-react",
|
|
6
6
|
"homepage": "https://xh.io",
|
package/promise/Promise.ts
CHANGED
|
@@ -202,8 +202,10 @@ const enhancePromise = promisePrototype => {
|
|
|
202
202
|
if (!options) return this;
|
|
203
203
|
|
|
204
204
|
const startTime = Date.now(),
|
|
205
|
-
doTrack = (
|
|
206
|
-
|
|
205
|
+
doTrack = (rejectReason: unknown = null) => {
|
|
206
|
+
const exception = rejectReason != null ? Exception.create(rejectReason) : null;
|
|
207
|
+
|
|
208
|
+
if (exception?.isRoutine) return;
|
|
207
209
|
|
|
208
210
|
const endTime = Date.now(),
|
|
209
211
|
opts: TrackOptions = isString(options) ? {message: options} : {...options};
|
|
@@ -222,7 +224,14 @@ const enhancePromise = promisePrototype => {
|
|
|
222
224
|
) {
|
|
223
225
|
opts.elapsed = null;
|
|
224
226
|
}
|
|
225
|
-
if (exception)
|
|
227
|
+
if (exception) {
|
|
228
|
+
opts.severity = 'ERROR';
|
|
229
|
+
opts.data = {
|
|
230
|
+
error: XH.exceptionHandler.sanitizeException(exception),
|
|
231
|
+
data: opts.data
|
|
232
|
+
};
|
|
233
|
+
opts.correlationId = opts.correlationId ?? exception.correlationId;
|
|
234
|
+
}
|
|
226
235
|
|
|
227
236
|
XH.track(opts);
|
|
228
237
|
};
|