Skip to content

Commit ee9985b

Browse files
committed
Surface curl errors
Errors in the invocation of `curl` were not being reported. Added `-f` flag to `curl`, return status checking, and printing the response body in case of errors.
1 parent 17f4cf5 commit ee9985b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dev_tools/ci/size-labeler.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,26 @@ function jq_file() {
8181
function api_call() {
8282
local -r endpoint="${1// /%20}" # love that our label names have spaces...
8383
local -r uri="https://api.github.com/repos/${GITHUB_REPOSITORY}"
84-
info "Calling: ${uri}/${endpoint}"
85-
curl -sSL \
84+
local -r url="${uri}/${endpoint}"
85+
local -r curl_opts=(
86+
-fsSL
87+
--connect-timeout 10 --max-time 20
8688
-H "Authorization: token ${GITHUB_TOKEN}" \
8789
-H "Accept: application/vnd.github.v3.json" \
8890
-H "X-GitHub-Api-Version:2022-11-28" \
8991
-H "Content-Type: application/json" \
90-
"${@:2}" \
91-
"${uri}/${endpoint}"
92+
)
93+
info "Calling: ${url}"
94+
set +e
95+
response_body=$(curl "${curl_opts[@]}" "${@:2}" "${url}")
96+
local exit_status=$?
97+
set -e
98+
if [[ $exit_status -ne 0 ]]; then
99+
error "GitHub API call failed (curl exit $exit_status) for ${url}"
100+
cat "$response_body"
101+
exit $exit_status
102+
fi
103+
return "$response_body"
92104
}
93105

94106
function compute_changes() {

0 commit comments

Comments
 (0)