chore: add statusText to HttpError and show in result as well
This commit is contained in:
parent
db67a91413
commit
876698825f
5 changed files with 9 additions and 7 deletions
|
|
@ -1,11 +1,13 @@
|
|||
export class HttpError extends Error {
|
||||
public readonly status: number;
|
||||
public readonly statusText: string;
|
||||
public readonly headers: Record<string, string[] | string | undefined>;
|
||||
|
||||
constructor(status: number, headers: Record<string, string[] | string | undefined>) {
|
||||
constructor(status: number, statusText: string, headers: Record<string, string[] | string | undefined>) {
|
||||
super();
|
||||
|
||||
this.status = status;
|
||||
this.statusText = statusText;
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ export class Fetcher {
|
|||
throw new BlockedError('unknown', httpCacheItem.policy.responseHeaders());
|
||||
}
|
||||
|
||||
throw new HttpError(httpCacheItem.status, responseHeaders);
|
||||
throw new HttpError(httpCacheItem.status, httpCacheItem.statusText, responseHeaders);
|
||||
};
|
||||
|
||||
private readonly determineTtl = (httpCacheItem: HttpCacheItem): number => {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ describe('resolve', () => {
|
|||
{
|
||||
url: new URL('https://example4.com'),
|
||||
isExternal: true,
|
||||
error: new HttpError(500, { 'x-foo': 'bar' }),
|
||||
error: new HttpError(500, 'Internal Server Error', { 'x-foo': 'bar' }),
|
||||
label: 'hoster.com',
|
||||
sourceId: '',
|
||||
meta: {
|
||||
|
|
|
|||
|
|
@ -170,8 +170,8 @@ export class StreamResolver {
|
|||
}
|
||||
|
||||
if (error instanceof HttpError) {
|
||||
this.logger.error(`${source}: HTTP status ${error.status}, headers: ${JSON.stringify(error.headers)}.`, ctx);
|
||||
return `❌ Request failed with status ${error.status}. Request-id: ${ctx.id}.`;
|
||||
this.logger.error(`${source}: HTTP status ${error.status} (${error.statusText}), headers: ${JSON.stringify(error.headers)}.`, ctx);
|
||||
return `❌ Request failed with status ${error.status} (${error.statusText}). Request-id: ${ctx.id}.`;
|
||||
}
|
||||
|
||||
const cause = (error as Error & { cause?: unknown }).cause;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ exports[`resolve adds error info 1`] = `
|
|||
"name": "WebStreamr N/A ⚠️ external",
|
||||
"title": "🌐 German 🇩🇪
|
||||
🔗 hoster.com
|
||||
❌ Request failed with status 500. Request-id: id.",
|
||||
❌ Request failed with status 500 (Internal Server Error). Request-id: id.",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -103,7 +103,7 @@ exports[`resolve adds error info 2`] = `
|
|||
"name": "WebStreamr N/A",
|
||||
"title": "🌐 German 🇩🇪
|
||||
🔗 hoster.com
|
||||
❌ Request failed with status 500. Request-id: id.",
|
||||
❌ Request failed with status 500 (Internal Server Error). Request-id: id.",
|
||||
"ytId": "E4WlUXrJgy4",
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue