From f2fb679102e0cfc7e57482c9d36a01c639625b85 Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Fri, 20 Sep 2024 00:55:51 -0400 Subject: [PATCH] [WIP] --- .../lwc/logger/logEntryBuilder.js | 21 +++++++++++++------ .../logger-engine/lwc/logger/loggerService.js | 6 ++++++ .../lwc/logger/loggerServiceTaskQueue.js | 5 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js b/nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js index d159ed77d..1b99b67e3 100644 --- a/nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js +++ b/nebula-logger/core/main/logger-engine/lwc/logger/logEntryBuilder.js @@ -106,17 +106,26 @@ const LogEntryBuilder = class { * @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods */ setError(error) { - if (!error) { + return this.setExceptionDetails(error); + } + + /** + * @description Sets the log entry event's exception fields + * @param {Error} exception The instance of a JavaScript `Error` object to use, or an Apex HTTP error to use + * @return {LogEntryBuilder} The same instance of `LogEntryBuilder`, useful for chaining methods + */ + setExceptionDetails(exception) { + if (!exception) { return this; } this.#componentLogEntry.error = {}; - if (error.body) { - this.#componentLogEntry.error.message = error.body.message; - this.#componentLogEntry.error.stackTrace = error.body.stackTrace; - this.#componentLogEntry.error.type = error.body.exceptionType; + if (exception.body) { + this.#componentLogEntry.error.message = exception.body.message; + this.#componentLogEntry.error.stackTrace = exception.body.stackTrace; + this.#componentLogEntry.error.type = exception.body.exceptionType; } else { - this.#componentLogEntry.error.message = error.message; + this.#componentLogEntry.error.message = exception.message; this.#componentLogEntry.error.stackTrace = new LoggerStackTrace().parse(error); this.#componentLogEntry.error.type = 'JavaScript.' + error.name; } diff --git a/nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js b/nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js index d7d5ff12f..8addc43c1 100644 --- a/nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js +++ b/nebula-logger/core/main/logger-engine/lwc/logger/loggerService.js @@ -27,6 +27,12 @@ const LoggerService = class { }); } + exception(message, exception, originStackTraceError) { + this.error(message, originStackTraceError).setExceptionDetails(exception); + this.saveLog(); + throw exception; + } + error(message, originStackTraceError) { return this._newEntry('ERROR', message, originStackTraceError); } diff --git a/nebula-logger/core/main/logger-engine/lwc/logger/loggerServiceTaskQueue.js b/nebula-logger/core/main/logger-engine/lwc/logger/loggerServiceTaskQueue.js index d75069b2f..15c28c83d 100644 --- a/nebula-logger/core/main/logger-engine/lwc/logger/loggerServiceTaskQueue.js +++ b/nebula-logger/core/main/logger-engine/lwc/logger/loggerServiceTaskQueue.js @@ -3,6 +3,11 @@ // See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. // //------------------------------------------------------------------------------------------------// +/* +This class handles enqueueing & executing any provided functions in the order that +they're specified, regardless if they're sync or async functions +*/ + /* eslint-disable @lwc/lwc/no-dupe-class-members */ export class LoggerServiceTaskQueue { #isProcessing = false;