-
Notifications
You must be signed in to change notification settings - Fork 216
Null safety for stringifyNonJSON function #22
Comments
@jmjdamen have you tried the latest version? I can't seem to be able to reproduce the issue with null payloads. Would be have a sample app to reproduce the issue? |
I've bumped into this when logging after a GET request that had no body. (I just noticed it this morning, not sure why I haven't seen it before.) |
Looks like it only happens if the GET request sets a content-type of application/json, which is not correct since there is no body with a GET request. Seems like a client error - specifying the content is JSON when it's not. |
@skuller yes we are using 2.0.1 The only way i can reproduce a similar error with a test app is to refer to a key in the payload that does not exist. POST JSON body via Postman Refer in JSON logger to a non existing field in JSON, which can occur due to an error or incomplete response from an API. payload: JSONLoggerModule::stringifyNonJSON(payload.data) This is not what happens in our actual services, we just log payload. The only thing i noticed from our original error in the logs is from the stack trace. This was in the stacktrace of an error before it went into the JSON logger in that error handler. Payload : null |
Hello @skuller @jmjdamen @revelant-doug , I seem to be getting this error rather often. In trying to understand the code more I used the Dataweave Playground (https://dwl.mule.club/) and if I copy the JSONLoggerModule into the script area and try to use it then it produces this error.
I have experienced the same error within flows where attempting to log the variables and there is no current variables defined and the map is blank. I did attempt to patch myself and it lowered the number of errors that I was seeing but sometimes see a different error. Wanted to see if anyone had any thoughts on this first? Thanks |
…lank then will just return the initial inputData
Here is the commit that I have changed locally that appears to resolve the issue as I am seeing it. Please provide feedback on these changes. Thanks |
Hello guys! |
I made some tests and works fine without an error, calling one get method without body:
|
When using the
JSONLoggerModule::stringifyNonJSON(payload)
function and the payload is null due to an error in a flow, the JSON logger throws an exception (which is quite valid as it can't parse null).However, in Mule flows sometimes the payload can be null due to exceptions, at the moment this is causing the JSON Logger to throw an error itself.
When the content field is configured with the function mentioned above, the content field contains.
"content" : "Error parsing expression. See logs for details."
This is not a really big issue however the error thrown because of this is:
Currently we solved this by check for null values in the JSON loggers content.
payload: if (payload != null) (JSONLoggerModule::stringifyNonJSON(payload)) else ""
This contains a manual action and can easily be forgotten.
It would be great if the function itself contains a null check in the underlying code, or see the alternative below.
So that the default expression (shown below) in the JSON logger content field can be used without any issues;
OR update the default expression to the one we used
i saw this can be done easily here , so we will probably start doing this ourselves, but everyone can benefit from this improval and it can be fixed in the function itself or in the schema with looks a bit more 'dirty'
The text was updated successfully, but these errors were encountered: