Skip to content

Commit 96eef38

Browse files
annaadamchukclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 63e18b4 commit 96eef38

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

app/AbstractUseStaleRequest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ protected function responseFromCache(): ?Response
3333
->setReadCache(false)
3434
->setWriteCache(true)
3535
->sync();
36-
} catch (\Throwable) {
37-
// Nobody cares, this is literally what use-stale is good at
36+
} catch (\Throwable $e) {
37+
$reRequest->onBackgroundRefreshFailed($e);
3838
}
3939
});
4040
}
@@ -78,6 +78,8 @@ public function purgeCache(): self
7878
return parent::purgeCache();
7979
}
8080

81+
protected function onBackgroundRefreshFailed(\Throwable $e): void {}
82+
8183
// Children of this class are *required* to thoughtfully implement their own PHP 8.1+ style serialization,
8284
// to work with `dispatch` in `responseFromCache`
8385
// https://php.watch/versions/8.1/serializable-deprecated

0 commit comments

Comments
 (0)