[Library | Trunk]: Add on error for some subjects calls.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59245 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
aa54f9460e
commit
07783fa92e
|
@ -2,35 +2,38 @@ import {Injectable} from '@angular/core';
|
|||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {Affiliation} from '../../utils/entities/CuratorInfo';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {properties} from "../../../../environments/environment";
|
||||
|
||||
@Injectable()
|
||||
export class AffiliationService {
|
||||
|
||||
|
||||
private affiliationsSubject: BehaviorSubject<Affiliation[]> = new BehaviorSubject([]);
|
||||
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
}
|
||||
|
||||
public initAffiliations(properties: EnvProperties, url: string): void {
|
||||
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).
|
||||
subscribe((affiliations) => {
|
||||
this.affiliationsSubject.next(affiliations);
|
||||
});
|
||||
|
||||
public initAffiliations(communityId: string): void {
|
||||
let url = properties.communityAPI + communityId + "/organizations";
|
||||
this.http.get<Affiliation[]>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url).subscribe((affiliations) => {
|
||||
this.affiliationsSubject.next(affiliations);
|
||||
},
|
||||
error => {
|
||||
this.affiliationsSubject.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public get affiliations(): Observable<Affiliation[]> {
|
||||
return this.affiliationsSubject.asObservable();
|
||||
}
|
||||
|
||||
|
||||
public updateAffiliation(url: string, affiliation: Affiliation) {
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'});
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
|
||||
return this.http.post<Affiliation>(url, JSON.stringify(affiliation), {headers: headers});
|
||||
}
|
||||
|
||||
|
||||
public deleteAffiliation(url: string, id: string) {
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept' : 'application/json'});
|
||||
return this.http.request('delete', url, { body: id, headers: headers})
|
||||
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
|
||||
return this.http.request('delete', url, {body: id, headers: headers})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ export class CommunitiesService {
|
|||
public communities: BehaviorSubject<CommunityInfo[]> = null;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.communities = new BehaviorSubject(null);
|
||||
this.communities = new BehaviorSubject([]);
|
||||
}
|
||||
|
||||
updateCommunities(properties: EnvProperties, url: string) {
|
||||
this.getCommunities(properties, url).subscribe(res => {
|
||||
this.communities.next(res);
|
||||
this.communities.next(res);
|
||||
}, error => {
|
||||
this.communities.error(error);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -27,7 +29,6 @@ export class CommunitiesService {
|
|||
|
||||
getCommunities(properties: EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
||||
//.map(res => <any> res.json())
|
||||
.pipe(map(res => this.parseCommunities(res)));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ export class CommunityService {
|
|||
resolve();
|
||||
},
|
||||
error => {
|
||||
this.community.next(null);
|
||||
this.community.error(error);
|
||||
resolve();
|
||||
})
|
||||
});
|
||||
|
@ -46,7 +46,6 @@ export class CommunityService {
|
|||
*/
|
||||
getCommunity(properties: EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
||||
//.map(res => <any> res.json())
|
||||
.pipe(map(res => this.parseCommunity(res)));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,29 +18,20 @@ export class UserManagementService {
|
|||
constructor(private http: HttpClient,
|
||||
private router: Router) {
|
||||
this.promise = new Promise<any>((resolve => {
|
||||
if(true) {
|
||||
const token = COOKIE.getCookie('AccessToken');
|
||||
if (!token) {
|
||||
this.getUserInfoSubject.next(null);
|
||||
resolve();
|
||||
} else {
|
||||
this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
|
||||
return this.parseUserInfo(userInfo);
|
||||
})).pipe(timeout(3000), catchError(() => {
|
||||
return of(null);
|
||||
})).subscribe(user => {
|
||||
this.getUserInfoSubject.next(user);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if(!COOKIE.getCookie('AccessToken')) {
|
||||
this.getUserInfoSubject.next(null);
|
||||
resolve();
|
||||
} else {
|
||||
this.updateUserInfo(resolve);
|
||||
}
|
||||
}
|
||||
const token = COOKIE.getCookie('AccessToken');
|
||||
if (!token) {
|
||||
this.getUserInfoSubject.next(null);
|
||||
resolve();
|
||||
} else {
|
||||
this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
|
||||
return this.parseUserInfo(userInfo);
|
||||
})).pipe(timeout(3000), catchError(() => {
|
||||
return of(null);
|
||||
})).subscribe(user => {
|
||||
this.getUserInfoSubject.next(user);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
}));
|
||||
this.router.events.subscribe(event => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
|
@ -53,7 +44,7 @@ export class UserManagementService {
|
|||
}
|
||||
|
||||
public getUserInfo(subject: boolean = true): Observable<User> {
|
||||
if(subject) {
|
||||
if (subject) {
|
||||
return this.getUserInfoSubject.asObservable();
|
||||
} else {
|
||||
return from(this.getUserInfoAsync());
|
||||
|
@ -67,7 +58,7 @@ export class UserManagementService {
|
|||
return of(null);
|
||||
})).subscribe(user => {
|
||||
this.getUserInfoSubject.next(user);
|
||||
if(resolve) {
|
||||
if (resolve) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -49,7 +49,7 @@ export class ConfigurationService {
|
|||
resolve();
|
||||
},
|
||||
error => {
|
||||
this.communityInformation.next(null);
|
||||
this.communityInformation.error(error);
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
|
|
@ -82,6 +82,9 @@ export class ISVocabulariesService {
|
|||
vocabularyRes => {
|
||||
this.vocabularies.get(vocabularyName).next(vocabularyRes);
|
||||
resolve();
|
||||
}, error => {
|
||||
this.vocabularies.get(vocabularyName).next(null);
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -100,14 +100,13 @@ export class StaticAutoCompleteComponent implements OnChanges{
|
|||
// this.afterListFetchedActions();
|
||||
this.sub = this._vocabulariesService.getVocabularyByType(this.vocabularyId, this.entityName, this.properties).subscribe(
|
||||
data => {
|
||||
this.list = (this.vocabularyId=="type" && this.entityName == "result" && data.length == 2)?data[0].concat(data[1]):data;
|
||||
this.afterListFetchedActions();
|
||||
|
||||
},
|
||||
err => {
|
||||
//console.log(err);
|
||||
this.handleError("Error getting vocabulary with id: "+this.vocabularyId+" for "+this.entityName, err);
|
||||
this.warningMessage = "An Error occured..."
|
||||
if(data) {
|
||||
this.list = (this.vocabularyId == "type" && this.entityName == "result" && data.length == 2) ? data[0].concat(data[1]) : data;
|
||||
this.afterListFetchedActions();
|
||||
} else {
|
||||
this.handleError("Error getting vocabulary with id: "+this.vocabularyId+" for "+this.entityName);
|
||||
this.warningMessage = "An Error occurred..."
|
||||
}
|
||||
}
|
||||
);
|
||||
}else if(this.fieldName && this.entityName){
|
||||
|
@ -308,7 +307,7 @@ export class StaticAutoCompleteComponent implements OnChanges{
|
|||
}
|
||||
}
|
||||
|
||||
private handleError(message: string, error) {
|
||||
private handleError(message: string, error = null) {
|
||||
console.error("Static Autocomplete (component): "+message, error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ export class SubscribeService {
|
|||
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
|
||||
this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
|
||||
this.isSubscribedSubject.next(isSubscribed);
|
||||
}, error => {
|
||||
this.isSubscribedSubject.error(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue