Skip auth header when reader API key missing

This commit is contained in:
Jurgis Sakalauskas
2025-10-18 11:55:07 +03:00
parent fa40cbcc37
commit e8134af44c
+7 -7
View File
@@ -26,19 +26,19 @@ export const readUrlMarkdown = async (rawUrl: string): Promise<string> => {
throw new HttpError(500, 'URL reader requires fetch support but it is unavailable.'); throw new HttpError(500, 'URL reader requires fetch support but it is unavailable.');
} }
if (!env.urlReader.apiKey) {
throw new HttpError(500, 'URL reader service is not configured.');
}
const normalizedTargetUrl = ensureHttpUrl(rawUrl); const normalizedTargetUrl = ensureHttpUrl(rawUrl);
const requestUrl = buildReaderUrl(normalizedTargetUrl); const requestUrl = buildReaderUrl(normalizedTargetUrl);
const apiKey = env.urlReader.apiKey?.trim();
const headers: Record<string, string> = {};
if (apiKey) {
headers.Authorization = `Bearer ${apiKey}`;
}
let response: Awaited<ReturnType<typeof fetch>>; let response: Awaited<ReturnType<typeof fetch>>;
try { try {
response = await fetch(requestUrl, { response = await fetch(requestUrl, {
headers: { headers
Authorization: `Bearer ${env.urlReader.apiKey}`
}
}); });
} catch { } catch {
throw new HttpError( throw new HttpError(