feat(core): Modify BaseExceptionFilter to include error properties in error logging #13681
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #13550
The class is defined as follows. This class includes the properties detail and code.
If thrown like this, the
detail
of the error and the information about42883
are not logged by the BaseExceptionFilter.As shown in the image below:
So, I created a protected method that logs the Error object to the console.
What is the new behavior?
Now, all the properties of the
Error
object processed by the BaseExceptionFilter can be seen in the logs.Does this PR introduce a breaking change?
The
error
method of the Logger class has been modified to log more than just the stack trace as a string when an Error object is passed. I'm not sure if this qualifies as a breaking change.Other information
I'm not sure if there's a specific reason why the console.error method shouldn't be used.
If it cannot be used, you can modify the handleUnknownError method in the BaseExceptionFilter as follows to check the properties of the error:
However, this approach is not exactly the same as using console.error; it does not provide color coding or emphasis on the stack trace, as shown in the image below.
If using the console.error method is not an option, we may need to manually create a string representation of the object to display as shown above.