apiLogger->send('fred', 'GET', self::URL, fn () => Http::timeout(30) ->retry(3, 200, fn (Throwable $e) => $this->shouldRetry($e)) ->throw() ->get(self::URL, [ 'series_id' => 'DCOILBRENTEU', 'api_key' => config('services.fred.api_key'), 'sort_order' => 'desc', 'limit' => 30, 'file_type' => 'json', ])); } catch (ConnectionException $e) { throw new BrentPriceFetchException("FRED connection failed: {$e->getMessage()}", previous: $e); } catch (RequestException $e) { throw new BrentPriceFetchException("FRED returned HTTP {$e->response->status()}", previous: $e); } $rows = collect($response->json('observations') ?? []) ->filter(fn (array $obs) => $obs['value'] !== '.') ->map(fn (array $obs) => [ 'date' => $obs['date'], 'price_usd' => (float) $obs['value'], ]) ->all(); return $rows === [] ? null : $rows; } private function shouldRetry(Throwable $e): bool { return $e instanceof ConnectionException || ($e instanceof RequestException && $e->response->serverError()); } }