diff --git a/spec/util/UnsubscriptionError-spec.ts b/spec/util/UnsubscriptionError-spec.ts index dad0143705f..f2f1db9b270 100644 --- a/spec/util/UnsubscriptionError-spec.ts +++ b/spec/util/UnsubscriptionError-spec.ts @@ -19,9 +19,7 @@ describe('UnsubscriptionError', () => { subscription.unsubscribe(); } catch (err) { expect(err instanceof UnsubscriptionError).to.equal(true); - expect(err.message).to.equal(`2 errors occurred during unsubscription: - 1) ${err1} - 2) ${err2}`); + expect(err.errors).to.deep.equal([err1, err2]); expect(err.name).to.equal('UnsubscriptionError'); } }); diff --git a/src/observable/dom/AjaxObservable.ts b/src/observable/dom/AjaxObservable.ts index b8fc058a7c7..427d1f1eee0 100644 --- a/src/observable/dom/AjaxObservable.ts +++ b/src/observable/dom/AjaxObservable.ts @@ -452,6 +452,9 @@ export class AjaxError extends Error { this.status = xhr.status; this.responseType = xhr.responseType || request.responseType; this.response = parseXhrResponse(this.responseType, xhr); + + this.name = 'AjaxError'; + (Object as any).setPrototypeOf(this, AjaxError.prototype); } } @@ -480,5 +483,6 @@ function parseXhrResponse(responseType: string, xhr: XMLHttpRequest) { export class AjaxTimeoutError extends AjaxError { constructor(xhr: XMLHttpRequest, request: AjaxRequest) { super('ajax timeout', xhr, request); + (Object as any).setPrototypeOf(this, AjaxTimeoutError.prototype); } } diff --git a/src/util/ArgumentOutOfRangeError.ts b/src/util/ArgumentOutOfRangeError.ts index 4384a2b465c..d3155f3361e 100644 --- a/src/util/ArgumentOutOfRangeError.ts +++ b/src/util/ArgumentOutOfRangeError.ts @@ -10,9 +10,8 @@ */ export class ArgumentOutOfRangeError extends Error { constructor() { - const err: any = super('argument out of range'); - ( this).name = err.name = 'ArgumentOutOfRangeError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('argument out of range'); + this.name = 'ArgumentOutOfRangeError'; + (Object as any).setPrototypeOf(this, ArgumentOutOfRangeError.prototype); } } diff --git a/src/util/EmptyError.ts b/src/util/EmptyError.ts index d1184ab189f..fbfe7bf88dd 100644 --- a/src/util/EmptyError.ts +++ b/src/util/EmptyError.ts @@ -10,9 +10,8 @@ */ export class EmptyError extends Error { constructor() { - const err: any = super('no elements in sequence'); - ( this).name = err.name = 'EmptyError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('no elements in sequence'); + this.name = 'EmptyError'; + (Object as any).setPrototypeOf(this, EmptyError.prototype); } } diff --git a/src/util/ObjectUnsubscribedError.ts b/src/util/ObjectUnsubscribedError.ts index 460a31029a6..fb005457e7d 100644 --- a/src/util/ObjectUnsubscribedError.ts +++ b/src/util/ObjectUnsubscribedError.ts @@ -9,9 +9,8 @@ */ export class ObjectUnsubscribedError extends Error { constructor() { - const err: any = super('object unsubscribed'); - ( this).name = err.name = 'ObjectUnsubscribedError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('object unsubscribed'); + this.name = 'ObjectUnsubscribedError'; + (Object as any).setPrototypeOf(this, ObjectUnsubscribedError.prototype); } } diff --git a/src/util/TimeoutError.ts b/src/util/TimeoutError.ts index c68adffac46..506249e94d6 100644 --- a/src/util/TimeoutError.ts +++ b/src/util/TimeoutError.ts @@ -7,9 +7,8 @@ */ export class TimeoutError extends Error { constructor() { - const err: any = super('Timeout has occurred'); - ( this).name = err.name = 'TimeoutError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('Timeout has occurred'); + + (Object as any).setPrototypeOf(this, TimeoutError.prototype); } } diff --git a/src/util/UnsubscriptionError.ts b/src/util/UnsubscriptionError.ts index 412164ed766..47999fc1e08 100644 --- a/src/util/UnsubscriptionError.ts +++ b/src/util/UnsubscriptionError.ts @@ -4,12 +4,10 @@ */ export class UnsubscriptionError extends Error { constructor(public errors: any[]) { - super(); - const err: any = Error.call(this, errors ? + super(errors ? `${errors.length} errors occurred during unsubscription: ${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : ''); - ( this).name = err.name = 'UnsubscriptionError'; - ( this).stack = err.stack; - ( this).message = err.message; + this.name = 'UnsubscriptionError'; + (Object as any).setPrototypeOf(this, UnsubscriptionError.prototype); } }