chore: log response headers for blocks
This commit is contained in:
parent
c5cc955d91
commit
d78dca3345
4 changed files with 7 additions and 5 deletions
|
|
@ -2,10 +2,12 @@ import { BlockedReason } from '../types';
|
|||
|
||||
export class BlockedError extends Error {
|
||||
public readonly reason: BlockedReason;
|
||||
public readonly headers: Record<string, string[] | string | undefined>;
|
||||
|
||||
constructor(reason: BlockedReason) {
|
||||
constructor(reason: BlockedReason, headers: Record<string, string[] | string | undefined>) {
|
||||
super();
|
||||
|
||||
this.reason = reason;
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ export class Fetcher {
|
|||
const responseHeaders = httpCacheItem.policy.responseHeaders();
|
||||
|
||||
if (httpCacheItem.policy.responseHeaders()['cf-mitigated'] === 'challenge') {
|
||||
throw new BlockedError('cloudflare_challenge');
|
||||
throw new BlockedError('cloudflare_challenge', httpCacheItem.policy.responseHeaders());
|
||||
}
|
||||
|
||||
if (httpCacheItem.status === 403) {
|
||||
throw new BlockedError('unknown');
|
||||
throw new BlockedError('unknown', httpCacheItem.policy.responseHeaders());
|
||||
}
|
||||
|
||||
throw new Error(`Fetcher error: ${httpCacheItem.status}: ${httpCacheItem.statusText}, response headers: ${JSON.stringify(responseHeaders)}`);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ describe('resolve', () => {
|
|||
{
|
||||
url: new URL('https://example.com'),
|
||||
isExternal: true,
|
||||
error: new BlockedError('cloudflare_challenge'),
|
||||
error: new BlockedError('cloudflare_challenge', {}),
|
||||
label: 'hoster.com',
|
||||
sourceId: '',
|
||||
meta: {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ 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}`, ctx);
|
||||
this.logger.warn(`${source}: Request was blocked. Reason: ${error.reason}, headers: ${JSON.stringify(error.headers)}`, ctx);
|
||||
|
||||
return '⚠️ Request was blocked.';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue