Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

mailPrefs.service.ts
1 1
import {Injectable} from '@angular/core';
2 2
import {Http, RequestOptions, Headers, Response} from '@angular/http';
3
import {Observable}     from 'rxjs/Observable';
3
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
4
import {Observable, throwError} from 'rxjs';
4 5
//import { HttpErrorResponse } from '@angular/common/http';
5 6

  
6 7
import {EnvProperties} from '../../utils/properties/env-properties';
......
8 9

  
9 10
@Injectable()
10 11
export class MailPrefsService {
11
    constructor(private http: Http ) {}
12
    constructor(private http: HttpClient ) {}
12 13

  
13 14
    getUserEmailPreferencesForCommunity (communityId:string, apiUrl:string):any {
14 15
      let url = apiUrl +"users/notification"+"?communityId="+communityId;
15 16

  
16 17
      return this.http.get(url, CustomOptions.getAuthOptions())
17
                      .map(request => <any> request.json())
18
                      //.map(request => <any> request.json())
18 19
                      //.do(request => console.info("Get user email preferences for communityId= "+communityId ));
19 20
                      //.catch(this.handleError);
20 21
    }
......
23 24
      let url = apiUrl +"users/notification";
24 25

  
25 26
      //var error: HttpErrorResponse = new HttpErrorResponse({"error": {"code": 204}, "status" : 204}); // doesn't work
26
      var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null});
27
      //var response: Response = new Response({"body" : {"code":200, "data": []}, "status": 200, "headers": null, "url": "", "merge": null});
27 28

  
28 29
      return this.http.get(url, CustomOptions.getAuthOptions())
29 30
                      //.timeoutWith(100, Observable.throw(response))   // goes to error
30 31
                      //.timeoutWith(100, Observable.of(response))      // goes to
31 32
                      //.do(request => console.info(request))
32
                      .map(request => <any> request.json())
33
                      //.map(request => <any> request.json())
33 34
                      //.do(request => console.info("Get user email preferences for OpenAIRE" ));
34 35
                      //.catch(this.handleError);
35 36
    }
......
39 40

  
40 41
      let body = JSON.stringify( notification );
41 42
      //console.warn('Json body:  : '+body);
42
      let headers = new Headers({ 'Content-Type': 'application/json' });
43
      let options = new RequestOptions({ headers: headers });
43
      //let headers = new Headers({ 'Content-Type': 'application/json' });
44
      //let options = new RequestOptions({ headers: headers });
44 45
      return this.http.post(url, body,  CustomOptions.getAuthOptionsWithBody())
45
                            .map(res => res.json())
46
                            //.map(res => res.json())
46 47
                            //.do(request => console.info("Insert Response:"+request.status) );
47 48
                            //.catch(this.handleError);
48 49
    }
49 50

  
50
    private handleError (error: Response) {
51
    private handleError (error: HttpErrorResponse) {
51 52
      // in a real world app, we may send the error to some remote logging infrastructure
52 53
      // instead of just logging it to the console
53 54
      console.log(error);
54
      return Observable.throw(error  || 'Server error');
55
      return throwError(error  || 'Server error');
55 56
    }
56 57
}

Also available in: Unified diff