Start Process using Rest - Exception gets thrown in plain html

Hello,

im trying to start a process using the rest api and want to implement my variable validation in the first service task.

I persist my process after the validation. How can i throw an Exception that the client recieves when he starts the process with invalid variables instead of the success response?

TL;DR: I want to throw an exception that the rest client recieves as application/json and not as html. (When starting the process using rest)

Hi @PhilippHeuer,

I’m afraid there is currently no such feature.

Cheers,
Thorben

@PhilippHeuer take a look at the example here: Limit number of concurrently running instances of a process definition

Its a workaround and requires some parsing to read the error message. What i have done in create a script task that does a check on the variables, and throw a error if the variables are not found.

see: https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/org/camunda/bpm/engine/delegate/VariableScope.html#hasVariables()

you can do execution.hasVariable('myVar'); //returns boolean

If you want to persist the data in the process i have had the client side look at the variables in return (https://docs.camunda.org/manual/7.7/reference/rest/process-definition/post-start-process-instance/ see the withVariablesInReturn option), and then use a script to eval the submitted variables and return a addtional var named something like validSubmittion = false

1 Like

Thanks for the idea. I’m now throwing a RuntimeException (like you) and attach a json response after the :. I will just have to do some regex magic to get my real json - it’s working :wink:

But it would be nice if we could add support for this in the camunda engine.