chore: do not log headers for known blocking reasons

This commit is contained in:
WebStreamr 2025-06-04 12:05:09 +00:00
parent a156e98831
commit 7ec7219ed4
No known key found for this signature in database
3 changed files with 31 additions and 1 deletions

View file

@ -73,6 +73,16 @@ describe('resolve', () => {
countryCode: 'de',
},
},
{
url: new URL('https://example.com'),
isExternal: true,
error: new BlockedError('unknown', {}),
label: 'hoster.com',
sourceId: '',
meta: {
countryCode: 'de',
},
},
{
url: new URL('https://example2.com'),
isExternal: true,

View file

@ -144,7 +144,11 @@ export class StreamResolver {
private readonly logErrorAndReturnNiceString = (ctx: Context, source: string, error: unknown): string => {
if (error instanceof BlockedError) {
this.logger.warn(`${source}: Request was blocked. Reason: ${error.reason}, headers: ${JSON.stringify(error.headers)}`, ctx);
if (error.reason === 'cloudflare_challenge') {
this.logger.warn(`${source}: Request was blocked via Cloudflare challenge.`, ctx);
} else {
this.logger.warn(`${source}: Request was blocked, headers: ${JSON.stringify(error.headers)}.`, ctx);
}
return '⚠️ Request was blocked.';
}

View file

@ -9,6 +9,14 @@ exports[`resolve adds error info 1`] = `
"name": "WebStreamr N/A ⚠️ external",
"title": "🌐 German 🇩🇪
🔗 hoster.com
⚠️ Request was blocked.",
},
{
"behaviorHints": {},
"externalUrl": "https://example.com/",
"name": "WebStreamr N/A ⚠️ external",
"title": "🌐 German 🇩🇪
🔗 hoster.com
⚠️ Request was blocked.",
},
{
@ -55,6 +63,14 @@ exports[`resolve adds error info 2`] = `
"name": "WebStreamr N/A",
"title": "🌐 German 🇩🇪
🔗 hoster.com
⚠️ Request was blocked.",
"ytId": "E4WlUXrJgy4",
},
{
"behaviorHints": {},
"name": "WebStreamr N/A",
"title": "🌐 German 🇩🇪
🔗 hoster.com
❌ Request failed. Request-id: id.",
"ytId": "E4WlUXrJgy4",
},