Skip to content

Instantly share code, notes, and snippets.

@lhns
Created December 12, 2022 15:48
Show Gist options
  • Save lhns/9b64b053e1012093aefb3576e2a30ca5 to your computer and use it in GitHub Desktop.
Save lhns/9b64b053e1012093aefb3576e2a30ca5 to your computer and use it in GitHub Desktop.
curlShowErrors() {
local exitCode=0
local output
local status
output="$(curl -sS -w '%{http_code}' "$@" | base64 -w 0)" || exitCode="$?"
status="$(printf %s "$output" | base64 -d | tail -c 3)"
if [[ "$status" =~ 2.. ]]; then
printf %s "$output" | base64 -d | head -c -3
else
printf %s "http $status: " >&2
printf %s "$output" | base64 -d | head -c -3 >&2
printf '\n' >&2
if [[ "$exitCode" == 0 ]]; then
exitCode="10$(printf %s "$status" | head -c 1)"
fi
fi
return "$exitCode"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment