Revision 55964
Added by Argiro Kokogiannaki almost 5 years ago
claimsByToken.service.ts | ||
---|---|---|
1 | 1 |
import {Injectable} from '@angular/core'; |
2 |
import {Http, Response} from '@angular/http'; |
|
3 |
import {Jsonp, URLSearchParams,ResponseOptions, RequestOptions, Headers} from '@angular/http'; |
|
4 |
import {Observable} from 'rxjs/Observable'; |
|
5 |
import 'rxjs/add/operator/do'; |
|
2 |
import {RequestOptions, Headers} from '@angular/http'; |
|
3 |
import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http"; |
|
4 |
import {throwError} from 'rxjs'; |
|
6 | 5 |
|
6 |
|
|
7 | 7 |
import { CustomOptions } from '../../services/servicesUtils/customOptions.class'; |
8 |
import {catchError} from "rxjs/operators"; |
|
8 | 9 |
|
9 | 10 |
@Injectable() |
10 | 11 |
export class ClaimsByTokenService { |
11 | 12 |
|
12 |
constructor(private http: Http ) {} |
|
13 |
constructor(private http: HttpClient ) {}
|
|
13 | 14 |
|
14 | 15 |
getClaims(openaireId: string, apiURL:string):any { |
15 | 16 |
|
... | ... | |
18 | 19 |
|
19 | 20 |
let key = url; |
20 | 21 |
|
21 |
return this.http.get(url, CustomOptions.getAuthOptions()) |
|
22 |
return this.http.get(url, CustomOptions.getAuthOptions());
|
|
22 | 23 |
//.map(res => <any> res.text()) |
23 |
.map(request => <any> request.json()); |
|
24 |
//.map(request => <any> request.json());
|
|
24 | 25 |
|
25 | 26 |
} |
26 | 27 |
|
... | ... | |
57 | 58 |
|
58 | 59 |
let body = JSON.stringify( claimsCurationInfo ); |
59 | 60 |
//console.warn('Json body: : '+body); |
60 |
let headers = new Headers({ 'Content-Type': 'application/json' }); |
|
61 |
let options = new RequestOptions({ headers: headers }); |
|
61 |
|
|
62 | 62 |
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) |
63 |
.map(res => res.json()) |
|
63 |
//.map(res => res.json())
|
|
64 | 64 |
//.do(request => console.info("Insert Response:"+request.status) ) |
65 |
.catch(this.handleError);
|
|
65 |
.pipe(catchError(this.handleError));
|
|
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
|
... | ... | |
74 | 74 |
|
75 | 75 |
let body = JSON.stringify( claimsCurationInfo ); |
76 | 76 |
//console.warn('Json body: : '+body); |
77 |
let headers = new Headers({ 'Content-Type': 'application/json' }); |
|
78 |
let options = new RequestOptions({ headers: headers }); |
|
77 |
|
|
79 | 78 |
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody()) |
80 |
.map(res => res.json()) |
|
81 |
.catch(this.handleError);
|
|
79 |
//.map(res => res.json())
|
|
80 |
.pipe(catchError(this.handleError));
|
|
82 | 81 |
} |
83 | 82 |
|
84 |
private handleError (error: Response) { |
|
83 |
private handleError (error: HttpErrorResponse) {
|
|
85 | 84 |
// in a real world app, we may send the error to some remote logging infrastructure |
86 | 85 |
// instead of just logging it to the console |
87 | 86 |
console.log(error); |
88 |
return Observable.throw(error || 'Server error'); |
|
87 |
return throwError(error || 'Server error'); |
|
88 |
//return Observable.throw(error || 'Server error'); |
|
89 | 89 |
} |
90 | 90 |
} |
Also available in: Unified diff
[Library|Trunk]
Merge into trunk branch angular7 rev 55729