Skip to content

Commit

Permalink
fix: 1702: Fix getExceptionMessageInfo() and add docu
Browse files Browse the repository at this point in the history
Fix getExceptionMessageInfo() function in exception-helper and add some
documentation to logger.exception

Closes: hyperledger#1702
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
  • Loading branch information
m-courtin committed Feb 8, 2022
1 parent 0a4fbd6 commit 8911ac6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ExceptionHelper {
const exceptionMessageInfo = this.getExceptionMessageInfo(exception);
const exceptionStackInfo = this.getExceptionStackInfo(exception);
let content = "";
let runtimeError = new RuntimeError(context, exceptionMessageInfo.message);
let runtimeError: RuntimeError | undefined = undefined;

if (exception instanceof Error) {
// scenario 1: exception is already an instance of Error / RuntimeError -> can be used directly
Expand Down Expand Up @@ -212,6 +212,9 @@ export class ExceptionHelper {
if (!exceptionHandled && isOfTypeString) {
message = customExceptionPrefix + exception;
exceptionHandled = true;
// as this scenario handles exception of string only type
// there is no other property and it is per se completely stringified
containsCompleteStringifiedException = true;
}

// scenario 4: handling of custom exceptions
Expand Down
8 changes: 8 additions & 0 deletions packages/cactus-common/src/main/typescript/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export class Logger {
}

/**
* The 'exception' method is retrieving and stringify-ing the complete exception content like message + stack + custom properties (if available) in a safe and secure way
* of any arbitrary exception or whatever it might be and logging it as an error thru the usage of this logger.error() functionality.
*
* So there is no need of dealing with different exception types or checks if a stack trace etc. is available -> all is done automatically here
* Only hand in the exception and maybe some optional, additional information / context can be provided as second parameter about the scenario where the exception happened
*
*
*
* Standard Exception Handling:
* ============================
* logger.exception(ex);
Expand Down

0 comments on commit 8911ac6

Please sign in to comment.