Commit 04406e07 authored by Diegodlh's avatar Diegodlh
Browse files

Add original request url property to HTTPResponseError

parent 8312305d
......@@ -43,7 +43,7 @@ function translateUrl(
} else {
// the response contains client (4xx) or server (5xx) error responses
// see https://github.com/node-fetch/node-fetch#handling-client-and-server-errors
const error = new HTTPResponseError(response);
const error = new HTTPResponseError(url, response);
if (response.status === 504) {
// response.body = upstream request timeout
reject(error);
......
......@@ -2,8 +2,10 @@ import { Response } from "node-fetch";
export class HTTPResponseError extends Error {
response: Response;
constructor(response: Response) {
url: string;
constructor(reqUrl: string, response: Response) {
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
this.url = reqUrl;
this.response = response;
this.name = "HTTPResponseError";
}
......
......@@ -79,7 +79,7 @@ class RevisionsApi {
try {
response = await fetch(url);
if (!response.ok) {
throw new HTTPResponseError(response);
throw new HTTPResponseError(url, response);
}
} catch (e) {
throw new Error(`Failed to fecth ${url}`);
......
......@@ -73,7 +73,7 @@ class HttpCache extends ResponseCache {
resolve(data);
} else {
this._refreshing = false;
reject(new HTTPResponseError(response));
reject(new HTTPResponseError(this.url, response));
}
})
.catch((reason) => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment