Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(api/redis): improve error handling on evictable redis (#4554)
Gergő Móriczfba5b0ccd866
diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.tsindex 95de50010..45998e46d 100644--- a/apps/api/src/controllers/auth.ts+++ b/apps/api/src/controllers/auth.ts@@ -44,6 +44,7 @@ import {import type { OAuthIntrospectionResponse } from "../services/oauth-token-introspection";import { verifyMcpDelegatedCredential } from "../lib/mcp-delegated-credential";import { autumnService } from "../services/autumn/autumn.service";+import { ReplyError } from "ioredis";function normalizedApiIsUuid(potentialUuid: string): boolean {// Check if the string is a valid UUID@@ -84,7 +85,9 @@ async function setCachedACUC(await setValue(cacheKeyACUC, JSON.stringify(acuc), 600, true);});} catch (error) {- logger.error(`Error updating cached ACUC ${cacheKeyACUC}: ${error}`);+ logger.error("Error updating cached ACUC", {+ error,+ });}}@@ -172,18 +175,38 @@ async function getACUC(const cacheKeyACUC = `acuc_${credentialPurpose}_${api_key}_${isExtract ? "extract" : "scrape"}`;if (useCache) {- const cachedACUC = await getValue(cacheKeyACUC);+ let cachedACUC: string | null;+ try {+ cachedACUC = await getValue(cacheKeyACUC);+ } catch (error) {+ if (+ error instanceof ReplyError ||+ (error instanceof Error &&+ (error as any).address &&+ (error as any).code &&+ error.name === "Error") ||+ (error instanceof Error && error.name === "MaxRetriesPerRequestError")+ ) {+ logger.warn(+ "Reading ACUC out of cache redis failed, treating as miss",+ {+ error,+ },+ );+ cachedACUC = null;+ } else {+ throw error;+ }+ }if (cachedACUC !== null) {try {return JSON.parse(cachedACUC);} catch (error) {logger.warn("Ignoring malformed ACUC cache entry", {- cacheKey: cacheKeyACUC,error,});void deleteKey(cacheKeyACUC).catch(deleteError => {logger.warn("Failed to delete malformed ACUC cache entry", {- cacheKey: cacheKeyACUC,error: deleteError,});});@@ -279,7 +302,10 @@ async function setCachedACUCTeam(await setValue(cacheKeyACUC, JSON.stringify(acuc), 600, true);});} catch (error) {- logger.error(`Error updating cached ACUC ${cacheKeyACUC}: ${error}`);+ logger.error("Error updating cached ACUC", {+ cacheKey: cacheKeyACUC,+ error,+ });}}@@ -308,7 +334,30 @@ export async function getACUCTeam(const cacheKeyACUC = `acuc_team_${team_id}_${isExtract ? "extract" : "scrape"}`;if (useCache) {- const cachedACUC = await getValue(cacheKeyACUC);+ let cachedACUC: string | null;+ try {+ cachedACUC = await getValue(cacheKeyACUC);+ } catch (error) {+ if (+ error instanceof ReplyError ||+ (error instanceof Error &&+ (error as any).address &&+ (error as any).code &&+ error.name === "Error") ||+ (error instanceof Error && error.name === "MaxRetriesPerRequestError")+ ) {+ logger.warn(+ "Reading ACUC out of cache redis failed, treating as miss",+ {+ cacheKey: cacheKeyACUC,+ error,+ },+ );+ cachedACUC = null;+ } else {+ throw error;+ }+ }if (cachedACUC !== null) {return JSON.parse(cachedACUC);}