Error Handling in Rest Connectors

Hello,

I am using camunda 8 and I have a subprocess in which contains a rest api connector in the error expression of that connector I wanted to make it something like this
if error.code = “400” and contains(error.message, inputErrrorCode) then
bpmnError(“ERROR”, “Business Error”)
else
null

where inputErrrorCode is a process variable passed to this subprocess for some reason that variable is always read as null , could anyone help me with this issue or what can I do as a work around ?

Can you share your BPMN file?

Kindly find this small example , I try to call an api that return an error and that error should be handled if the input i give the bpm at start is part of the error message but it doesn’t work

restCall.bpmn (6.2 KB)

Hi @Mariam_Heiba, unfortunately, the error expression doesn’t have access to process variables, so you can only use the connector output data and static values in such expressions.

is there any kind of workaround for this issue if i don’t want to pass the error code statically ?

I’d maybe consider this:

  1. In your error expression, raise a BPMN error for any connector error. Store relevant details in the error code or in error variables.
  2. Catch all BPMN errors using a boundary error event without an error definition
  3. Use FEEL script tasks and/or conditional gateways to evaluate the error code and variables to decide on the appropriate handling strategy.

But this will not be a complete workaround, since you might lose a chance to raise an incident for errors that shouldn’t be handled as business errors (depending on how precisely you can define your initial error expression only by using static values).

2 Likes

This appears to be relatively simple to resolve. According to the BPMN you sent, we have the flow below:
image

I assigned a value to your errorCode variable, the final value of which will depend on you:
image

I compared the error code with its variable (you can also compare the error message instead of the error code) and did:

I think this answers your question right?

Could you send me this bpm please, as when I try this the errorCode is read as null and I don’t to seem to be able to compare its value

Of course:
restcall (1).bpmn (6.7 KB)

Tell us if this is the solution :+1:

1 Like

I think in your solution in the error boundary event you didn’t specify a global error reference so it actually catches all errors and the if condition isn’t actually satisfied it just catches all errors

Did your question have to do with comparing the error with its variable or with global error capture? What I showed above is the treatment of an error according to a specific condition that compares an error message or error code with its variable, to treat the error globally just do it in else.

I’m still confused about what you really need

What I mean is when I tried to run the BPM you send the condition is not being evaluated correctly and doesn’t even get in the if condition even if the error.code equals 404 as the BPM sees the errorCode variable as null
apparently we can’t use a process variable in error expression block as it doesn’t have access to them

If what you say were true and in fact we could not use a process variable in the error expression block, the BPMN in the attached image would not be fulfilled, on another level of example I compared 2 variables which I assigned the same value on purpose and I passed a message that would be assigned to an error boundary event output variable.




the condition actually passes because it’s true as they both evaluate as null so they are both equal to null but if you try to make the equation like this
if(errorCode = “001”) the condition won’t be correct and it won’t be fulfilled
and if you make the condition if(errorCode=null) the condition will be fulfilled

Ow ok, I got it, it seemed simple enough not to be possible but apparently you’re right.

Just wondering, is inputErrrorCode supposed to have 3 r’s instead of 2?