Created
December 12, 2022 15:48
-
-
Save lhns/9b64b053e1012093aefb3576e2a30ca5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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