diff --git a/src/util/ajax.js b/src/util/ajax.js index 04ffa8e1580..f39cb83dc40 100644 --- a/src/util/ajax.js +++ b/src/util/ajax.js @@ -42,9 +42,19 @@ export type RequestParameters = { class AJAXError extends Error { status: number; - constructor(message: string, status: number) { + url: string; + constructor(message: string, status: number, url: string) { super(message); this.status = status; + this.url = url; + + // work around for https://github.com/Rich-Harris/buble/issues/40 + this.name = this.constructor.name; + this.message = message; + } + + toString() { + return `${this.name}: ${this.message} (${this.status}): ${this.url}`; } } @@ -75,7 +85,7 @@ exports.getJSON = function(requestParameters: RequestParameters, callback: Callb } callback(null, data); } else { - callback(new AJAXError(xhr.statusText, xhr.status)); + callback(new AJAXError(xhr.statusText, xhr.status, requestParameters.url)); } }; xhr.send(); @@ -100,7 +110,7 @@ exports.getArrayBuffer = function(requestParameters: RequestParameters, callback expires: xhr.getResponseHeader('Expires') }); } else { - callback(new AJAXError(xhr.statusText, xhr.status)); + callback(new AJAXError(xhr.statusText, xhr.status, requestParameters.url)); } }; xhr.send();