fix: enhance error handling for unauthorized Jina API key

This commit is contained in:
Han Xiao 2025-06-12 14:03:37 -07:00
parent 8e3d34bcca
commit 034e984d15

View File

@ -46,6 +46,7 @@ import { buildImageReferences, buildReferences } from "./tools/build-ref";
import { logInfo, logError, logDebug, logWarning } from './logging'; import { logInfo, logError, logDebug, logWarning } from './logging';
import { researchPlan } from './tools/research-planner'; import { researchPlan } from './tools/research-planner';
import { reduceAnswers } from './tools/reducer'; import { reduceAnswers } from './tools/reducer';
import { AxiosError } from 'axios';
async function wait(seconds: number) { async function wait(seconds: number) {
logDebug(`Waiting ${seconds}s...`); logDebug(`Waiting ${seconds}s...`);
@ -323,6 +324,10 @@ async function executeSearchQueries(
query, query,
error: error instanceof Error ? error.message : String(error) 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; continue;
} finally { } finally {
await wait(STEP_SLEEP); await wait(STEP_SLEEP);