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