Improved response checking in linux script

Added check that prevents throwing a JSON parsing error when the server is down
This commit is contained in:
Fabian Schliski 2019-07-09 19:17:12 +02:00 committed by GitHub
parent c89bd9c654
commit 1d8f588d48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,14 @@ EOF
upload() {
RESPONSE="$(curl -F "token={{ token }}" -F "upload=@${1}" {{ upload_url }})";
if jq -e . >/dev/null 2>&1 <<<"$RESPONSE"; then
# Response is JSON
echo;
else
notify-send "Error: Uploading returned unexpected response" "Response: ${RESPONSE}";
exit 1;
fi
if [[ "$(echo "${RESPONSE}" | jq -r '.message')" == "OK." ]]; then
URL="$(echo "${RESPONSE}" | jq -r '.url')";