fix: context.error was not printed because JSON.stringify(Error) doesn't work by default in JS #19217
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.
Previously, the logged message
Request is resolved with the SSR rendering error
was printed byOptimizedSsrEngine
alongside with the JSON.strinfied propertycontext.error
which ended up looking like an empty object{}
(even if it was not empty, but a real Error object instead!). It was because of a natural thing in JavaScript:JSON.stringify()
invoked on object of typeError
always returns{}
(it's becasue properties of theError
object are non-enumerable; for more see https://stackoverflow.com/a/68640559/11734692).Now the
context.error
property is printed as a pretty error string. How it's done: thecontext.error
property is first converted into a pretty string with the help of theformatWithOptions()
function of nativenode:util
package. Btw.formatWithOptions()
is the same mechanism that is used by theconsole.log()
under the hood to convert a given object into a string.And when performing later the
JSON.stringify()
on thecontext
object, thecontext.error
property has been already converted into a pretty string describing an error. SoJSON.stringify
simply re-returns this string. See the following example of a pretty error string:As you can see in the example above, some nested properties of the
[cause]
property, are described byArray
orMap
. This has been fixed also in this PR, by configuringdepth: 10
(instead of the default2
) in the options passed to theformatWithOptions()
util.TODO:
closes https://jira.tools.sap/browse/CXSPA-8360