Move error handler to CacheManager from Client.

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2021-05-19 10:49:54 +02:00
parent c7dad92187
commit f2d9f5ecb9
4 changed files with 103 additions and 17 deletions
+6 -5
View File
@@ -2,15 +2,16 @@
'@backstage/backend-common': patch
---
Plugin developers may now provide handlers for connection errors emitted by cache stores.
All cache-related connection errors are now handled and logged by the cache manager. App Integrators may provide an optional error handler when instantiating the cache manager if custom error handling is needed.
```typescript
// Providing an error handler
const cacheClient = somePluginCache.getClient({
defaultTtl: 3600000,
const cacheManager = CacheManager.fromConfig(config, {
onError: e => {
logger.error(`There was a cache connection problem: ${e.message}`);
execOtherErrorHandlingLogic();
if (isSomehowUnrecoverable(e)) {
gracefullyShutThingsDown();
process.exit(1);
}
},
});
```