diff --git a/ratatoskr.sh b/ratatoskr.sh index 9399fe8..8d4087c 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -76,9 +76,21 @@ post_music() { local text="[$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}"')]" local link="(https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b))" local json=$(jq -n --arg status "$text$link" --arg spoiler_text "Music" --arg content_type "text/markdown" '{status: $status, spoiler_text: $spoiler_text, content_type: $content_type}') - curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \ + local result + result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \ -d "$json" \ - "${instanceURL}/api/v1/statuses" + "${instanceURL}/api/v1/statuses")" + # Check for errors + if [[ $? -ne 0 ]]; then + echo "there was a problem contacting the server" + exit 1 + fi + local error="$(echo "$result" | jq -r '.error')" + if [[ "$error" != "null" ]]; then + echo "Error: $error" + exit 1 + fi + echo "Music posted!" exit 0 }