Catching Rejections
To catch rejections we use the subscriber's error and complete callbacks.
1
import { HttpClient } from '@angular/http/common';
2
import { Injectable } from '@angular/core';
3
4
@Injectable()
5
export class AuthService {
6
7
constructor(private http: HttpClient) {}
8
9
login(username, password) {
10
const payload = {
11
username: username,
12
password: password
13
};
14
15
this.http.post(`${ BASE_URL }/auth/login`, payload)
16
.pipe(map(response => response.json()))
17
.subscribe(
18
authData => this.storeToken(authData.id_token),
19
(err) => console.error(err),
20
() => console.log('Authentication Complete')
21
);
22
}
23
}
Copied!
Last modified 3mo ago
Copy link