This commit is contained in:
parent
a206ec509d
commit
8b1cef6944
1 changed files with 13 additions and 9 deletions
|
|
@ -84,25 +84,28 @@ query_api() {
|
|||
dbg " -> API attempt #$attempt for $domain"
|
||||
|
||||
tmpfile=$(mktemp)
|
||||
TEMP_FILES+=("$tmpfile")
|
||||
http_code=$(curl -sS --compressed \
|
||||
curl -sS --compressed \
|
||||
-m 10 --connect-timeout 5 \
|
||||
--retry 2 --retry-connrefused \
|
||||
-H 'Accept: application/json' \
|
||||
-w '%{http_code}' \
|
||||
-o "$tmpfile" \
|
||||
"${API_URL}${domain}" 2>>"$DEBUG_LOG" || true)
|
||||
"${API_URL}${domain}" 2>>"$DEBUG_LOG" || true
|
||||
|
||||
http_code=$(tail -n1 "$tmpfile")
|
||||
body=$(cat "$tmpfile")
|
||||
|
||||
preview="$(printf '%s' "$body" | tr '\n' ' ' | cut -c1-400)"
|
||||
dbg " -> HTTP=$http_code, preview=${preview}"
|
||||
|
||||
if [ "$http_code" = "200" ] && jq -e . "$tmpfile" >/dev/null 2>&1; then
|
||||
echo "$tmpfile" # возвращаем путь к tmp json файлу
|
||||
cat "$tmpfile" # вернём тело JSON напрямую
|
||||
rm -f "$tmpfile"
|
||||
return 0
|
||||
fi
|
||||
|
||||
rm -f "$tmpfile"
|
||||
|
||||
if [ "$attempt" -ge "$max_attempts" ]; then
|
||||
ERRORS["$domain"]="http_${http_code}_or_invalid_json"
|
||||
dbg " -> Failed after $attempt attempts, preview=${preview}"
|
||||
|
|
@ -116,6 +119,7 @@ query_api() {
|
|||
done
|
||||
}
|
||||
|
||||
|
||||
if [ ! -f "$INPUT_FILE" ]; then
|
||||
err "Input file not found: $INPUT_FILE"
|
||||
exit 3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue