Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix(rxjs): add rxjs-compat and use throwError instead of Observable.t…
Browse files Browse the repository at this point in the history
…hrowError
  • Loading branch information
sahil143 authored and sudsen committed Oct 10, 2018
1 parent a3d8868 commit de41d7d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"rimraf": "2.6.2",
"run-sequence": "2.2.0",
"rxjs": "6.0.0",
"rxjs-compat": "^6.3.3",
"script-ext-html-webpack-plugin": "1.8.7",
"semantic-release": "8.2.0",
"style-loader": "0.19.0",
Expand Down
4 changes: 2 additions & 2 deletions src/app/effects/infotip.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { provideMockActions } from '@ngrx/effects/testing';
import { cold, hot } from 'jasmine-marbles';

import { Notifications } from 'ngx-base';
import { Observable, of } from 'rxjs';
import { Observable, of, throwError } from 'rxjs';
import { Action } from 'rxjs/scheduler/Action';
import * as Actions from '../actions/infotip.actions';
import { InfotipService } from '../services/infotip.service';
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('InfotipEffects', () => {
const action = new Actions.Get();
const error = new Actions.GetError();

infotipService.getInfotips.and.returnValue(Observable.throw(new Error()));
infotipService.getInfotips.and.returnValue(throwError(new Error()));

actions = hot('--a-', { a: action });
const expected = cold('--b', { b: error });
Expand Down
6 changes: 3 additions & 3 deletions src/app/services/area.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable, of as ObservableOf } from 'rxjs';
import { Observable, of as ObservableOf, throwError } from 'rxjs';
import { catchError, first, map } from 'rxjs/operators';

import { Injectable } from '@angular/core';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class AreaService {
return ObservableOf<AreaModel[]>([] as AreaModel[]);
}
} else {
return Observable.throw('nospace');
return throwError('nospace');
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ export class AreaService {
}
}),
catchError(err => {
return Observable.throw(new Error(err.message));
return throwError(new Error(err.message));
})
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/custom-query.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, throwError } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
import { CustomQueryModel } from '../models/custom-query.model';
import { HttpClientService } from '../shared/http-module/http.service';
Expand Down Expand Up @@ -66,7 +66,7 @@ export class CustomQueryService {
} else {
console.log(str, error.message);
}
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
}

}
4 changes: 2 additions & 2 deletions src/app/services/filter.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable, Subject } from 'rxjs';
import { Observable, Subject, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { FilterModel } from '../models/filter.model';
import { HttpClientService } from '../shared/http-module/http.service';
Expand Down Expand Up @@ -142,7 +142,7 @@ export class FilterService {
map(response => response.data as FilterModel[]),
catchError((error: Error | any) => {
console.log('API returned error: ', error.message);
return Observable.throw('Error - [FilterService - getFilters]' + error.message); // TODO ng6: use throwError from rxjs 6
return throwError('Error - [FilterService - getFilters]' + error.message);
})
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/services/work-item.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
import { Logger } from 'ngx-base';
import { Spaces, WIT_API_URL } from 'ngx-fabric8-wit';
import { UserService } from 'ngx-login-client';
import { Observable, of } from 'rxjs';
import { Observable, of, throwError } from 'rxjs';

import { delay } from 'rxjs/operators';
import {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Unit Test :: WorkItemService', () => {
const wiService = TestBed.get(WorkItemService);
wiService['baseApiUrl'] = 'link/to/spaces/';
wiService.httpClientService.get.and.returnValue(
Observable.throw(new Error('Internal service error')).pipe(delay(100))
throwError(new Error('Internal service error')).pipe(delay(100))
);
spyOn(wiService, 'notifyError');
wiService.getWorkItems('', {}).subscribe(
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('Unit Test :: WorkItemService', () => {
it('getMoreWorkItems :: Should call notifyError if error response comes', done => {
const wiService = TestBed.get(WorkItemService);
wiService.httpClientService.get.and.returnValue(
Observable.throw(new Error('Internal service error')).pipe(delay(100))
throwError(new Error('Internal service error')).pipe(delay(100))
);
spyOn(wiService, 'notifyError');
wiService.getMoreWorkItems('some/url').subscribe(
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('Unit Test :: WorkItemService', () => {
const wiService = TestBed.get(WorkItemService);
wiService['baseApiUrl'] = 'link/to/';
wiService.httpClientService.get.and.returnValue(
Observable.throw(new Error('Internal service error')).pipe(delay(100))
throwError(new Error('Internal service error')).pipe(delay(100))
);
spyOn(wiService, 'notifyError');
// We are providing the space name as empty to the function
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('Unit Test :: WorkItemService', () => {
const wiService = TestBed.get(WorkItemService);
wiService['baseApiUrl'] = 'link/to/';
wiService.httpBackendClient.get.and.returnValue(
Observable.throw(new Error('Internal service error')).pipe(delay(100))
throwError(new Error('Internal service error')).pipe(delay(100))
);
spyOn(wiService, 'notifyError');
// We are providing the space name as empty to the function
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('Unit Test :: WorkItemService', () => {
it('getWorkItemTypes :: Should call notifyError on error', done => {
const wiService = TestBed.get(WorkItemService);
wiService.httpClientService.get.and.returnValue(
Observable.throw(new Error('Internal server error')).pipe(delay(100))
throwError(new Error('Internal server error')).pipe(delay(100))
);
spyOn(wiService, 'notifyError');
wiService.getWorkItemTypes('link/to/types').subscribe(
Expand Down
30 changes: 15 additions & 15 deletions src/app/services/work-item.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable } from '@angular/core';

import { Observable, of as ObservableOf } from 'rxjs';
import { Observable, of as ObservableOf, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';

import { Logger } from 'ngx-base';
Expand Down Expand Up @@ -53,7 +53,7 @@ export class WorkItemService {

private handleError(error: Error | any, msg: string) {
this.notifyError(msg, error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Getting work items failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand Down Expand Up @@ -138,11 +138,11 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Getting more work items failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
} else {
return Observable.throw('No more item found'); // TODO ng6: use throwError from rxjs 6
return throwError('No more item found');
}
}

Expand All @@ -166,7 +166,7 @@ export class WorkItemService {
map(item => item.data),
catchError((error: Error | any) => {
this.notifyError('Getting work item data failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
} else {
Expand All @@ -175,7 +175,7 @@ export class WorkItemService {
map(i => i.data),
catchError((error: Error | any) => {
this.notifyError('Getting work item data failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export class WorkItemService {
map(response => [response.data as Link[], response.included]),
catchError((error: Error | any) => {
this.notifyError('Getting linked items data failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand All @@ -250,7 +250,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Getting work item type information failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Updating work item failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand All @@ -318,7 +318,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Creating comment failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand All @@ -341,7 +341,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Updating comment failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand All @@ -356,7 +356,7 @@ export class WorkItemService {
.pipe(
catchError((error: Error | any) => {
this.notifyError('Deleting comment failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand All @@ -373,7 +373,7 @@ export class WorkItemService {
map(d => d.data),
catchError((error: Error | any) => {
this.notifyError('Getting link meta info failed (forward).', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand Down Expand Up @@ -524,7 +524,7 @@ export class WorkItemService {
}),
catchError((error: Error | any) => {
this.notifyError('Getting work item type info failed.', error);
return Observable.throw(new Error(error.message)); // TODO ng6: use throwError from rxjs 6
return throwError(new Error(error.message));
})
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/http-module/http.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpBackend, HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, timer } from 'rxjs';
import { Observable, throwError, timer } from 'rxjs';
import { flatMap, retryWhen } from 'rxjs/operators';

@Injectable()
Expand Down Expand Up @@ -35,9 +35,9 @@ export class HttpClientService {
console.log('########### Now offline #############', error);
return timer(++count * 1000); // TODO ng6: use timer from rxjs 6
} else if (error.status == 500 || error.status == 401) { // Server error :: Try 3 times then throw error
return ++count >= 3 ? Observable.throw(error) : timer(1000); // TODO ng6: use throwError, timer from rxjs 6
return ++count >= 3 ? throwError(error) : timer(1000);
} else {
return Observable.throw(error); // TODO ng6: use throwError from rxjs 6
return throwError(error);
}
})
);
Expand Down

0 comments on commit de41d7d

Please sign in to comment.