refactor: use a 'case' for greater clarity
This commit is contained in:
1 parent
ecb180c0c5
commit
bac3d65ede
1 file changed
+12
-10
@@ -1050,16 +1050,18 @@ http_call() {
|
|||||||
shift 3
|
shift 3
|
||||||
CURL_TMPOUT=/tmp/weave_curl_out_$$
|
CURL_TMPOUT=/tmp/weave_curl_out_$$
|
||||||
HTTP_CODE=$(curl -o $CURL_TMPOUT -w '%{http_code}' --connect-timeout 3 -s -S -X $http_verb "$@" http://$addr$url) || return $?
|
HTTP_CODE=$(curl -o $CURL_TMPOUT -w '%{http_code}' --connect-timeout 3 -s -S -X $http_verb "$@" http://$addr$url) || return $?
|
||||||
if [ "$HTTP_CODE" = "404" ] ; then # Swallow the message for 404
|
case "$HTTP_CODE" in
|
||||||
retval=4
|
2??) # 2xx -> not an error; output response on stdout
|
||||||
# anything else not beginning with a 2 is an error: send the message to stderr
|
[ -f $CURL_TMPOUT ] && cat $CURL_TMPOUT
|
||||||
elif [ "$HTTP_CODE" = "${HTTP_CODE#2}" ] ; then
|
retval=0
|
||||||
[ -f $CURL_TMPOUT ] && cat $CURL_TMPOUT >&2
|
;;
|
||||||
retval=1
|
404) # treat as error but swallow response
|
||||||
else
|
retval=4
|
||||||
[ -f $CURL_TMPOUT ] && cat $CURL_TMPOUT
|
;;
|
||||||
retval=0
|
*) # anything else is an error; output response on stderr
|
||||||
fi
|
[ -f $CURL_TMPOUT ] && cat $CURL_TMPOUT >&2
|
||||||
|
retval=1
|
||||||
|
esac
|
||||||
rm -f $CURL_TMPOUT
|
rm -f $CURL_TMPOUT
|
||||||
return $retval
|
return $retval
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user