Problem with SendGrid connector error handling expressions

I use the following expression as the Error handling property (Error Exression fx) of a SendGrid outbound connector.

if is defined(error) 
then bpmnError(
  "Custom error message") 
else null


In case of an error, the attached “Catch Error Boundary Event” is triggered correctly.
In case of succes (sending emial), an flow node error occurred the message :

“Failed to evaluate expression ‘=if is defined(error) then bpmnError( “CustomErrorCode”, “Custom error message”) else null’ in context ‘[Ljava.lang.Object;@a9d5327’. Reason: Context is null”

In my opinion the error expression is correct according to the documentation. How to write the error expression so that it does not throw an error in case of a correct SendGrid task?.

Environment Camunda-Platform 8.4.2 / Camund-Connectors 8.4.4 (docker self managed)