From 5dccd96f347a637ca779eb06e86d77e78910a0f7 Mon Sep 17 00:00:00 2001 From: zcong1993 Date: Thu, 29 Aug 2019 17:30:31 +0800 Subject: [PATCH] expect response --- entrypoint.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b55ee5c..199e60a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,14 @@ echo "body: $INPUT_BODY" url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}" -curl -s "$url" \ +HTTP_RESPONSE=$(curl -s --write-out "HTTPSTATUS:%{http_code}" "$url" \ -H 'Content-Type: application/json' \ - -d "${INPUT_BODY}" + -d "${INPUT_BODY}") + +# extract the body +HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + +if [ ! "$HTTP_BODY" = '{"errcode":0,"errmsg":"ok"}' ]; then + echo "Error Response: ${HTTP_RESPONSE}" + exit 1 +fi