Skip to content

Commit

Permalink
fix(ajax): RxJS v6 TimeoutError is missing name property
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Bonnet committed May 7, 2018
1 parent 7e4cef4 commit 576d943
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ describe('Observable.ajax', () => {
});

expect(error instanceof Rx.AjaxError).to.be.true;
expect(error.name).to.equal('AjaxError');
expect(error.message).to.equal('ajax error 404');
expect(error.status).to.equal(404);
});
Expand Down Expand Up @@ -843,7 +844,7 @@ describe('Observable.ajax', () => {
delete root.XMLHttpRequest.prototype.onreadystatechange;
});

it('should work fine when XMLHttpRequest ontimeout property is monkey patched', function() {
it('should work fine when XMLHttpRequest ontimeout property is monkey patched', function(done) {
Object.defineProperty(root.XMLHttpRequest.prototype, 'ontimeout', {
set(fn: (e: ProgressEvent) => any) {
const wrapFn = (ev: ProgressEvent) => {
Expand All @@ -867,7 +868,8 @@ describe('Observable.ajax', () => {
Rx.Observable.ajax(ajaxRequest)
.subscribe({
error(err) {
/* expected, ignore */
expect(err.name).to.equal('AjaxTimeoutError');
done();
}
});

Expand Down
1 change: 1 addition & 0 deletions src/internal/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ function parseXhrResponse(responseType: string, xhr: XMLHttpRequest) {
export class AjaxTimeoutError extends AjaxError {
constructor(xhr: XMLHttpRequest, request: AjaxRequest) {
super('ajax timeout', xhr, request);
this.name = 'AjaxTimeoutError';
(Object as any).setPrototypeOf(this, AjaxTimeoutError.prototype);
}
}

0 comments on commit 576d943

Please sign in to comment.