From d90278aff8305ed7b44c837d301f216bc468b298 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Tue, 22 Oct 2024 11:08:44 +0200 Subject: port some more of the error handling from it_url::get to it_url::get_multi --- it_url.class | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/it_url.class b/it_url.class index 772b7d1..cfeaa1d 100644 --- a/it_url.class +++ b/it_url.class @@ -163,7 +163,7 @@ function _get($p = []) return $result; } -function retry_warranted($result, $status) +static function retry_warranted($result, $status) { return $result ? it::match(self::$forceretry, $status) : !it::match('^(204|4..)$', $status); } @@ -466,7 +466,10 @@ static function get_multi($p=null) { $key = $keys[(int)$info['handle']]; $content = curl_multi_getcontent($info['handle']); - if (isset($p['postprocess'])) + $status = curl_getinfo($handles[$key], CURLINFO_RESPONSE_CODE); + if ($status >= 400 && (!$p['body_on_fail'] || $p['keepfailed'])) + $content = false; + else if (isset($p['postprocess'])) $content = $p['postprocess']($content, ['it_error' => $retries[$key] < $p['retries'] ? false : (array)$p['it_error'] + ['title' => "invalid content from " . $urls[$key]]]); EDC('reqtimings', $key, $info['result'], (gettimeofday(true) - $start) * 1000); @@ -475,7 +478,7 @@ static function get_multi($p=null) if (!$p['noresults']) $results_unordered[$key] = $content; - if (it::match(self::$forceretry, curl_getinfo($handles[$key], CURLINFO_RESPONSE_CODE)) && $retries[$key]++ < $p['retries']) + if (self::retry_warranted($content, $status) && $retries[$key]++ < $p['retries']) { $sleepuntils[$key] = microtime(true) + $p['retrysleep']; } -- cgit v1.2.3