Skip to content

Commit

Permalink
Merge pull request #3656 from bbonnet/fix-timeout-error-name
Browse files Browse the repository at this point in the history
fix(ajax): RxJS v6 TimeoutError is missing name property
  • Loading branch information
benlesh authored May 9, 2018
2 parents f3e9c0d + 44042d0 commit 940a121
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 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
5 changes: 4 additions & 1 deletion spec/operators/timeout-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ describe('Observable.prototype.timeout', () => {
it('should emit and error of an instanceof TimeoutError on timeout', () => {
const e1 = cold('-------a--b--|');
const result = e1.timeout(50, rxTestScheduler);
let error;
result.subscribe(() => {
throw new Error('this should not next');
}, err => {
expect(err).to.be.an.instanceof(Rx.TimeoutError);
error = err;
}, () => {
throw new Error('this should not complete');
});
rxTestScheduler.flush();
expect(error).to.be.an.instanceof(Rx.TimeoutError);
expect(error.name).to.equal('TimeoutError');
});

it('should not timeout if source completes within absolute timeout period', () => {
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);
}
}
2 changes: 1 addition & 1 deletion src/internal/util/TimeoutError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
export class TimeoutError extends Error {
constructor() {
super('Timeout has occurred');

this.name = 'TimeoutError';
(Object as any).setPrototypeOf(this, TimeoutError.prototype);
}
}

0 comments on commit 940a121

Please sign in to comment.