Skip to content

Commit 6b3e0fa

Browse files
committed
fix: improve HTTP download error handling for wget and curl
- Updated `http_download_curl` to log HTTP errors using `log_err` instead of `log_debug`. - Modified `http_download_wget` to check HTTP status codes, mirroring curl's behavior. - Return exit status 1 for non-200 responses in `http_download_wget`. - Standardized error logging across both download functions.
1 parent 2691aac commit 6b3e0fa

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

install.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ http_download_curl() {
301301
code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url")
302302
fi
303303
if [ "$code" != "200" ]; then
304-
log_debug "http_download_curl received HTTP status $code"
304+
log_err "http_download_curl received HTTP status $code"
305305
return 1
306306
fi
307307
return 0
@@ -311,20 +311,20 @@ http_download_wget() {
311311
source_url=$2
312312
header=$3
313313
if [ -z "$header" ]; then
314-
wget -q -O "$local_file" "$source_url"
314+
code=$(wget --server-response --quiet -O "$local_file" "$source_url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1)
315315
else
316-
wget -q --header "$header" -O "$local_file" "$source_url"
316+
code=$(wget --server-response --quiet --header "$header" -O "$local_file" "$source_url" 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1)
317317
fi
318+
if [ "$code" != "200" ]; then
319+
log_err "http_download_wget received HTTP status $code"
320+
return 1
321+
fi
322+
return 0
318323
}
319324
http_download() {
320325
log_debug "http_download $2"
321-
if is_command curl; then
322-
http_download_curl "$@"
323-
return
324-
elif is_command wget; then
325-
http_download_wget "$@"
326-
return
327-
fi
326+
http_download_wget "$@"
327+
return
328328
log_crit "http_download unable to find wget or curl"
329329
return 1
330330
}

0 commit comments

Comments
 (0)