Commit 1233dc95 authored by Lukas Schauer's avatar Lukas Schauer

exit with error message if curl has problems connecting (fixes #133)

parent 5ef4d86b
...@@ -238,15 +238,25 @@ _openssl() { ...@@ -238,15 +238,25 @@ _openssl() {
http_request() { http_request() {
tempcont="$(mktemp -t XXXXXX)" tempcont="$(mktemp -t XXXXXX)"
set +e
if [[ "${1}" = "head" ]]; then if [[ "${1}" = "head" ]]; then
statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -I)" statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -I)"
curlret="${?}"
elif [[ "${1}" = "get" ]]; then elif [[ "${1}" = "get" ]]; then
statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}")" statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}")"
curlret="${?}"
elif [[ "${1}" = "post" ]]; then elif [[ "${1}" = "post" ]]; then
statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -d "${3}")" statuscode="$(curl -s -w "%{http_code}" -o "${tempcont}" "${2}" -d "${3}")"
curlret="${?}"
else else
set -e
_exiterr "Unknown request method: ${1}" _exiterr "Unknown request method: ${1}"
fi fi
set -e
if [[ ! "${curlret}" = "0" ]]; then
_exiterr "Problem connecting to server (curl returned with ${curlret})"
fi
if [[ ! "${statuscode:0:1}" = "2" ]]; then if [[ ! "${statuscode:0:1}" = "2" ]]; then
echo " + ERROR: An error occurred while sending ${1}-request to ${2} (Status ${statuscode})" >&2 echo " + ERROR: An error occurred while sending ${1}-request to ${2} (Status ${statuscode})" >&2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment