Browse Source

docs(core): Add error handling to example Redis session cache

Michael Bromley 2 years ago
parent
commit
46a4b74983
1 changed files with 20 additions and 8 deletions
  1. 20 8
      packages/core/src/config/session-cache/session-cache-strategy.ts

+ 20 - 8
packages/core/src/config/session-cache/session-cache-strategy.ts

@@ -84,22 +84,34 @@ export type CachedSession = {
  *   }
  *
  *   async get(sessionToken: string): Promise<CachedSession | undefined> {
- *     const retrieved = await this.client.get(this.namespace(sessionToken));
- *     if (retrieved) {
- *       try {
- *         return JSON.parse(retrieved);
- *       } catch (e: any) {
- *         Logger.error(`Could not parse cached session data: ${e.message}`, loggerCtx);
+ *     try {
+ *       const retrieved = await this.client.get(this.namespace(sessionToken));
+ *       if (retrieved) {
+ *         try {
+ *           return JSON.parse(retrieved);
+ *         } catch (e: any) {
+ *           Logger.error(`Could not parse cached session data: ${e.message}`, loggerCtx);
+ *         }
  *       }
+ *     } catch (e: any) {
+ *       Logger.error(`Could not get cached session: ${e.message}`, loggerCtx);
  *     }
  *   }
  *
  *   async set(session: CachedSession) {
- *     await this.client.set(this.namespace(session.token), JSON.stringify(session));
+ *     try {
+ *       await this.client.set(this.namespace(session.token), JSON.stringify(session));
+ *     } catch (e: any) {
+ *       Logger.error(`Could not set cached session: ${e.message}`, loggerCtx);
+ *     }
  *   }
  *
  *   async delete(sessionToken: string) {
- *     await this.client.del(this.namespace(sessionToken));
+ *     try {
+ *       await this.client.del(this.namespace(sessionToken));
+ *     } catch (e: any) {
+ *       Logger.error(`Could not delete cached session: ${e.message}`, loggerCtx);
+ *     }
  *   }
  *
  *   clear() {