## What Hardens `CurrencyConversionService` against a slow/unreachable external FX-rate CDN, which was crashing `/api/cashflow/trend`. ## Sentry - Fixes PHP-LARAVEL-2X — `RuntimeException: Failed to fetch currency rates ... cURL error 28: Operation timed out` - Fixes PHP-LARAVEL-31 — `FatalError: Maximum execution time of 30 seconds exceeded` (Guzzle CurlFactory) ## Root cause For a historical date the service walked up to 8 lookback dates × 2 URLs at a **10s timeout each** (~160s worst case → 30s PHP fatal), and a single network timeout threw a `RuntimeException` that 500'd the whole request. ## Changes - **Bounded timeouts**: 3s connect / 5s total per request. - **Abort on unreachable source**: a connection/timeout error stops the date walk (after trying the fallback host) instead of repeating the same timeout for every candidate date. 404s still walk back to earlier releases. - **Graceful degradation**: failures return an empty rate map instead of throwing — conversions already fall back to `0.0` on missing rates, so the trend endpoint no longer 500s. - **Persistent cache**: historical releases cached 30d (immutable), `latest` 6h, unavailable results 10m (dampens retries during an outage). ## Tests - Updated the former "throws" test to assert graceful degradation to `0.0`. - Added: timeout aborts the date walk after 2 attempts; rates cache across service instances. - All 12 tests pass. |
||
|---|---|---|
| .. | ||
| .pest | ||
| Browser | ||
| Feature | ||
| Performance | ||
| Unit | ||
| Pest.php | ||
| TestCase.php | ||
| bootstrap.php | ||