Last active
July 6, 2021 15:01
-
-
Save lhns/d3eea7c783b2b97c3d94995d72feeb16 to your computer and use it in GitHub Desktop.
similar to curl --fail-with-body
This file contains hidden or 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
| #!/bin/bash | |
| curlFailWithBody() { | |
| exec {fd}>&1 | |
| local httpCode="$(curl "$@" -w '%{http_code}' -o >(cat >&"$fd"))" | |
| local exitCode="$?" | |
| exec {fd}<&- | |
| if (($exitCode == 0 && ($httpCode < 200 || $httpCode > 299))); then | |
| exitCode=22 | |
| if (($httpCode >= 400 && $httpCode <= 555)); then | |
| exitCode=$(($httpCode - 300)) | |
| fi | |
| fi | |
| return "$exitCode" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment