fix curl handler
This commit is contained in:
parent
42f0ccc615
commit
5856d99d7d
@ -118,20 +118,6 @@ function select_storage() {
|
|||||||
exit 205
|
exit 205
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for network connectivity (IPv4 & IPv6)
|
|
||||||
#function check_network() {
|
|
||||||
# local CHECK_URLS=("8.8.8.8" "1.1.1.1" "9.9.9.9" "2606:4700:4700::1111" "2001:4860:4860::8888" "2620:fe::fe")
|
|
||||||
#
|
|
||||||
# for url in "${CHECK_URLS[@]}"; do
|
|
||||||
# if ping -c 1 -W 2 "$url" &>/dev/null; then
|
|
||||||
# return 0 # Success: At least one connection works
|
|
||||||
# fi
|
|
||||||
# done
|
|
||||||
#
|
|
||||||
# msg_error "No network connection detected. Check your internet connection."
|
|
||||||
# exit 101
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Test if ID is in use
|
# Test if ID is in use
|
||||||
if qm status "$CTID" &>/dev/null || pct status "$CTID" &>/dev/null; then
|
if qm status "$CTID" &>/dev/null || pct status "$CTID" &>/dev/null; then
|
||||||
echo -e "ID '$CTID' is already in use."
|
echo -e "ID '$CTID' is already in use."
|
||||||
|
@ -113,9 +113,9 @@ silent() {
|
|||||||
|
|
||||||
run_curl() {
|
run_curl() {
|
||||||
if [ "$VERB" = "no" ]; then
|
if [ "$VERB" = "no" ]; then
|
||||||
curl --retry 0 -fsSL "$@" >/dev/null 2>&1
|
curl "$@" 2>/tmp/curl_error.log >/dev/null
|
||||||
else
|
else
|
||||||
curl --retry 0 -fsSL "$@"
|
curl "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ curl_handler() {
|
|||||||
run_curl "${args[@]}"
|
run_curl "${args[@]}"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
else
|
else
|
||||||
result=$(run_curl "${args[@]}" 2>/dev/null)
|
result=$(run_curl "${args[@]}")
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -158,11 +158,16 @@ curl_handler() {
|
|||||||
|
|
||||||
if ((attempt >= max_retries)); then
|
if ((attempt >= max_retries)); then
|
||||||
stop_spinner
|
stop_spinner
|
||||||
__curl_err_handler "$exit_code" "$url"
|
if [ -s /tmp/curl_error.log ]; then
|
||||||
|
local curl_stderr
|
||||||
|
curl_stderr=$(</tmp/curl_error.log)
|
||||||
|
rm -f /tmp/curl_error.log
|
||||||
|
fi
|
||||||
|
__curl_err_handler "$exit_code" "$url" "$curl_stderr"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "\r\033[K${INFO}${YW}Retry $attempt/$max_retries in ${delay}s...${CL}" >&2
|
$STD printf "\r\033[K${INFO}${YW}Retry $attempt/$max_retries in ${delay}s...${CL}" >&2
|
||||||
sleep "$delay"
|
sleep "$delay"
|
||||||
((attempt++))
|
((attempt++))
|
||||||
done
|
done
|
||||||
@ -174,6 +179,8 @@ curl_handler() {
|
|||||||
__curl_err_handler() {
|
__curl_err_handler() {
|
||||||
local exit_code="$1"
|
local exit_code="$1"
|
||||||
local target="$2"
|
local target="$2"
|
||||||
|
local curl_msg="$3"
|
||||||
|
|
||||||
case $exit_code in
|
case $exit_code in
|
||||||
1) msg_error "Unsupported protocol: $target" ;;
|
1) msg_error "Unsupported protocol: $target" ;;
|
||||||
2) msg_error "Curl init failed: $target" ;;
|
2) msg_error "Curl init failed: $target" ;;
|
||||||
@ -183,7 +190,7 @@ __curl_err_handler() {
|
|||||||
7) msg_error "Connection failed: $target" ;;
|
7) msg_error "Connection failed: $target" ;;
|
||||||
9) msg_error "Access denied: $target" ;;
|
9) msg_error "Access denied: $target" ;;
|
||||||
18) msg_error "Partial file transfer: $target" ;;
|
18) msg_error "Partial file transfer: $target" ;;
|
||||||
22) msg_error "HTTP error (e.g. 404) - try again later: $target" ;;
|
22) msg_error "HTTP error (e.g. 400/404): $target" ;;
|
||||||
23) msg_error "Write error on local system: $target" ;;
|
23) msg_error "Write error on local system: $target" ;;
|
||||||
26) msg_error "Read error from local file: $target" ;;
|
26) msg_error "Read error from local file: $target" ;;
|
||||||
28) msg_error "Timeout: $target" ;;
|
28) msg_error "Timeout: $target" ;;
|
||||||
@ -198,6 +205,8 @@ __curl_err_handler() {
|
|||||||
78) msg_error "Remote file not found (404): $target" ;;
|
78) msg_error "Remote file not found (404): $target" ;;
|
||||||
*) msg_error "Curl failed with code $exit_code: $target" ;;
|
*) msg_error "Curl failed with code $exit_code: $target" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
[[ -n "$curl_msg" ]] && printf "%s\n" "$curl_msg" >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user