From 96eef38d145d9d735c97b8ae8cf8a218a928e505 Mon Sep 17 00:00:00 2001 From: annaadamchuk Date: Fri, 17 Apr 2026 14:51:56 -0400 Subject: [PATCH] feat: add onBackgroundRefreshFailed hook to AbstractUseStaleRequest Replaces the silent catch block in the background refresh closure with a no-op hook method. Consumers can override onBackgroundRefreshFailed() to add logging or metrics without the library forcing a specific behaviour. Co-Authored-By: Claude Sonnet 4.6 --- app/AbstractUseStaleRequest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/AbstractUseStaleRequest.php b/app/AbstractUseStaleRequest.php index 279f665..82697c3 100644 --- a/app/AbstractUseStaleRequest.php +++ b/app/AbstractUseStaleRequest.php @@ -33,8 +33,8 @@ protected function responseFromCache(): ?Response ->setReadCache(false) ->setWriteCache(true) ->sync(); - } catch (\Throwable) { - // Nobody cares, this is literally what use-stale is good at + } catch (\Throwable $e) { + $reRequest->onBackgroundRefreshFailed($e); } }); } @@ -78,6 +78,8 @@ public function purgeCache(): self return parent::purgeCache(); } + protected function onBackgroundRefreshFailed(\Throwable $e): void {} + // Children of this class are *required* to thoughtfully implement their own PHP 8.1+ style serialization, // to work with `dispatch` in `responseFromCache` // https://php.watch/versions/8.1/serializable-deprecated