diff options
author | Nathan Gass | 2024-10-22 11:08:44 +0200 |
---|---|---|
committer | Nathan Gass | 2024-10-22 11:08:44 +0200 |
commit | d90278aff8305ed7b44c837d301f216bc468b298 (patch) | |
tree | fc7bec25d2ddd84cfa52d65668430a6eddb1947a | |
parent | 1c657c2264c17dc2980bbce2f63ddad7546e96d5 (diff) | |
download | itools-d90278aff8305ed7b44c837d301f216bc468b298.tar.gz itools-d90278aff8305ed7b44c837d301f216bc468b298.tar.bz2 itools-d90278aff8305ed7b44c837d301f216bc468b298.zip |
port some more of the error handling from it_url::get to it_url::get_multi
-rw-r--r-- | it_url.class | 9 |
1 files 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']; } |