Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 695 Bytes

README.md

File metadata and controls

30 lines (23 loc) · 695 Bytes

Catching Rejections

To catch rejections we use the subscriber's error and complete callbacks.

import { HttpClient } from '@angular/http/common';
import { Injectable } from '@angular/core';

@Injectable()
export class AuthService {

  constructor(private http: HttpClient) {}

  login(username, password) {
    const payload = {
      username: username,
      password: password
    };

    this.http.post(`${ BASE_URL }/auth/login`, payload)
      .pipe(map(response => response.json()))
      .subscribe(
        authData => this.storeToken(authData.id_token),
        (err) => console.error(err),
        () => console.log('Authentication Complete')
      );
  }
}