From 034e984d153d9a85ec2bd356bd1914bec22cb977 Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Thu, 12 Jun 2025 14:03:37 -0700 Subject: [PATCH] fix: enhance error handling for unauthorized Jina API key --- src/agent.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/agent.ts b/src/agent.ts index d2278af..def3e41 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -46,6 +46,7 @@ import { buildImageReferences, buildReferences } from "./tools/build-ref"; import { logInfo, logError, logDebug, logWarning } from './logging'; import { researchPlan } from './tools/research-planner'; import { reduceAnswers } from './tools/reducer'; +import { AxiosError } from 'axios'; async function wait(seconds: number) { logDebug(`Waiting ${seconds}s...`); @@ -323,6 +324,10 @@ async function executeSearchQueries( query, error: error instanceof Error ? error.message : String(error) }); + // check if the error is 401 + if (error instanceof AxiosError && error.response?.status === 401 && (searchProvider === 'jina' || searchProvider === 'arxiv')) { + throw new Error('Unauthorized Jina API key'); + } continue; } finally { await wait(STEP_SLEEP);