From 15bde01fb6f8b7b6e44684fe8ed845db73b46b0f Mon Sep 17 00:00:00 2001 From: fbt Date: Sat, 28 Nov 2026 02:04:34 +0000 Subject: [PATCH] check api response exit code Signed-off-by: fbt --- ufw | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ufw b/ufw index 7dfda9d..2316433 100755 --- a/ufw +++ b/ufw @@ -89,6 +89,10 @@ get_album_id() { --data-urlencode "name=$1" \ --data-urlencode "secret=$secret" \ "$cfg_service_url/albumctl.json?m=new" ) + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } get_api_status <<< "$api_response" @@ -165,6 +169,10 @@ upload() { "${misc_curl_args[@]}" \ -A 'zerofiles.org upload script' \ "$cfg_service_url/maw.json" ) + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } if (( flag_shortlink )); then if (( flag_directlink )); then @@ -210,6 +218,10 @@ get_shortlink() { api_response=$( curl --data-urlencode "url=$url" \ --data-urlencode "secret=$secret" \ "$cfg_service_url/shrink.json" ) + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } get_api_status <<< "$api_response" @@ -254,7 +266,11 @@ _mktemp() { get_my_ip() { declare api_response api_status api_status_message my_ip - api_response=$( curl "$cfg_service_url/ip.json" ) + api_response=$( curl -f "$cfg_service_url/ip.json" ) + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } get_api_status <<< "$api_response" @@ -274,6 +290,10 @@ login() { api_response=$( curl --get \ --data-urlencode "login=$login" \ "$cfg_service_url/token_request.json" ) + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } if get_api_status <<< "$api_response"; then printf 'Check your email.\n' @@ -307,6 +327,11 @@ get_token() { } api_response=$(curl -b "$cfg_file.cookiejar" -sl "$cfg_service_url/api_token.json") + (( $? )) && { + err "Failed to get a response from the API, folding." + return 1 + } + rm -f "$cfg_file.cookiejar" if get_api_status <<< "$api_response"; then