Raising an incident via inline script vs incident generated by exception


#1

Hi, we have an http connector with an inline script to process the response:

var response = connector.getVariable(“response”);
var statusCode = connector.getVariable(“statusCode”);

if (statusCode != 200) {
throw new Error(connector.getVariable(“response”));
}
else {
JSON.parse(response).value;
}

If the statusCode is not 200 this results in an incident and the workflow stops, which is what we want. However there is a lot of information logged in via a ScriptEvaluationException that is very verbose and not really needed.

I had a look at: Error creating incident via javascript but this seems to have been classified as a “hack”.

Is there a way to create an incident and avoid having to throw the Error in order to get the workflow to stop?


#2

Look at the delegate execution API and the comments further down in the mentioned forum post: the execution.createIncident() method replaced the need to use the internal API.


#3

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.10/org/camunda/bpm/engine/delegate/DelegateExecution.html See the createIncident() methods


#4

Hi

@StephenOTT, thank you very much for the suggestion.
We have attempted to use the createIncident method in the output parameter of http-connector.

var statusCode = connector.getVariable("statusCode");
if (statusCode != 201) {
  execution.createIncident();
}

From further reading we’ve found that the execution variable is not accessible in the http-connector’s scope as described in this thread Error creating incident via javascript and JIRA https://app.camunda.com/jira/browse/CAM-8937 you posted.

I’m a bit confused by this comment “Look at the delegate execution API and the comments further down in the mentioned forum post: the execution.createIncident() method replaced the need to use the internal API.” Is there another way we can invoke " execution.createIncident()" in the http-connector’s scope?

Thanks in advance.


#5

You can use Create and Resolve Incidents through Scripts(Javascript examples) (Internal API) to get the execution/parent scope. But this is internal API. I would recommend that you just use a end-execution listener that Evals a local variable in the connector to veal the status code. Or recreate http connector as a java delegate or look at: Replacing Http-Connector with Jsoup usage