From c2612b873f43dac14dfedccfaca8f9ebffe24392 Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 23 Mar 2023 07:41:59 -0400 Subject: [PATCH] added check result function when running a process model from the shell script --- spiffworkflow-backend/bin/run_process_model_with_api | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spiffworkflow-backend/bin/run_process_model_with_api b/spiffworkflow-backend/bin/run_process_model_with_api index f8b3a6c73..c62e43ada 100755 --- a/spiffworkflow-backend/bin/run_process_model_with_api +++ b/spiffworkflow-backend/bin/run_process_model_with_api @@ -27,6 +27,15 @@ fi modified_process_model_identifier=$(tr '/' ':' <<<"$process_model_identifier") +function check_result_for_error() { + local result="$1" + error_code=$(jq '.error_code' <<<"$result") + if [[ -n "$error_code" ]]; then + >&2 echo "ERROR: Failed to run process instance. Received error: $result" + exit 1 + fi +} + function process_next_task() { local next_task="$1" @@ -37,6 +46,7 @@ function process_next_task() { if grep -qE "Manual ?Task" <<<"$task_type" && [[ "${task_state}" == "READY" ]]; then next_task=$(curl --silent -X PUT "${BACKEND_BASE_URL}/v1.0/tasks/${process_instance_id}/${task_guid}" -H "Authorization: Bearer $access_token") + check_result_for_error "$next_task" process_next_task "$next_task" elif [[ "$(jq '.ok' <<<"$next_task")" == "null" ]]; then echo -e "\n\nThe next task is not a Manual Task and requires user input. It must be completed manually." @@ -55,5 +65,6 @@ if ! grep -qE '^[0-9]+$' <<<"$process_instance_id"; then fi result=$(curl --silent -X POST "${BACKEND_BASE_URL}/v1.0/process-instances/${modified_process_model_identifier}/${process_instance_id}/run" -H "Authorization: Bearer $access_token") +check_result_for_error "$result" next_task=$(jq '.next_task' <<<"$result") process_next_task "$next_task"