From 38fc1b8122c705bde52850611835f54c30f0b6b7 Mon Sep 17 00:00:00 2001 From: kexkey Date: Mon, 3 Jun 2019 17:31:20 -0400 Subject: [PATCH] Better error handling for the notify function --- proxy_docker/app/script/notify.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proxy_docker/app/script/notify.sh b/proxy_docker/app/script/notify.sh index 5525151..c2558ce 100644 --- a/proxy_docker/app/script/notify.sh +++ b/proxy_docker/app/script/notify.sh @@ -13,6 +13,7 @@ notify_web() { local returncode local response local http_code + local curl_code # We use the pid as the response-topic, so there's no conflict in responses. trace "[notify_web] mosquitto_rr -h broker -W 21 -t notifier -e \"response/$$\" -m \"{\"response-topic\":\"response/$$\",\"cmd\":\"web\",\"url\":\"${url}\",\"body\":\"${body}\"}\"" @@ -23,17 +24,19 @@ notify_web() { # The response looks like this: {"curl_code":0,"http_code":200,"body":"..."} where the body # is the base64(response body) but we don't need the response content here. trace "[notify_web] response=${response}" + curl_code=$(echo "${response}" | jq ".curl_code" | tr -d '"') + trace "[notify_web] curl_code=${curl_code}" http_code=$(echo "${response}" | jq ".http_code" | tr -d '"') trace "[notify_web] http_code=${http_code}" - if [ "${returncode}" -eq "0" ]; then + if [ "${curl_code}" -eq "0" ] && [ "${returncode}" -eq "0" ]; then if [ "${http_code}" -lt "400" ]; then return 0 else return ${http_code} fi else - return ${returncode} + return ${curl_code} || ${returncode} fi } \ No newline at end of file