diff --git a/multicurl.sh b/multicurl.sh index 026c37ac..7ae6d1f5 100755 --- a/multicurl.sh +++ b/multicurl.sh @@ -47,7 +47,14 @@ for url in "${urls[@]}"; do # null result (a lagging endpoint that doesn't have the requested block/data yet). # Without the result==null check the first endpoint's {"result":null} was accepted as # success and the remaining fallback URLs were never tried. - if cat "$temp_file" | jq -e 'has("error") or (.result == null)' > /dev/null 2>&1; then + # $temp_file only exists when curl was called with -o (see the -o loop above). + # When a caller omits -o, the body is already in $output, so reading cat "" would + # emit "cat: '': No such file or directory". Read from whichever place holds the body. + response_body="$output" + if [ -n "$temp_file" ]; then + response_body=$(cat "$temp_file") + fi + if echo "$response_body" | jq -e 'has("error") or (.result == null)' > /dev/null 2>&1; then continue # Try the next URL fi