Skip to content

Commit

Permalink
fix(auth): error caught
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Sep 13, 2019
1 parent 73542d0 commit 6d89e07
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/auth/src/lib/shared/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';

import { Observable, BehaviorSubject, of } from 'rxjs';
import { tap } from 'rxjs/operators';
import { tap, catchError } from 'rxjs/operators';

import { ConfigService, LanguageService } from '@igo2/core';
import { Base64 } from '@igo2/utils';
Expand Down Expand Up @@ -128,17 +128,19 @@ export class AuthService {
}

private loginCall(body, headers) {
return this.http
.post(`${this.options.url}/login`, body, { headers })
.pipe(
tap((data: any) => {
this.tokenService.set(data.token);
const tokenDecoded = this.decodeToken();
if (tokenDecoded && tokenDecoded.user && tokenDecoded.user.locale) {
this.languageService.setLanguage(tokenDecoded.user.locale);
}
this.authenticate$.next(true);
})
);
return this.http.post(`${this.options.url}/login`, body, { headers }).pipe(
tap((data: any) => {
this.tokenService.set(data.token);
const tokenDecoded = this.decodeToken();
if (tokenDecoded && tokenDecoded.user && tokenDecoded.user.locale) {
this.languageService.setLanguage(tokenDecoded.user.locale);
}
this.authenticate$.next(true);
}),
catchError(err => {
err.error.caught = true;
throw err;
})
);
}
}

0 comments on commit 6d89e07

Please sign in to comment.