Commit 8d3b1759 authored by achinta's avatar achinta

feat: handel error

parent ba26db00
...@@ -20,7 +20,7 @@ export class LogoutService { ...@@ -20,7 +20,7 @@ export class LogoutService {
} }
public logout(): void { public logout(message:string = 'Successfully Logged out'): void {
if (this.isBrowser) { if (this.isBrowser) {
...@@ -30,7 +30,7 @@ export class LogoutService { ...@@ -30,7 +30,7 @@ export class LogoutService {
this._router.navigate([RequestMapperService.LOGIN_URL]).then(() => { this._router.navigate([RequestMapperService.LOGIN_URL]).then(() => {
// window.location.reload(); // window.location.reload();
this._toaster.success('Successfully Logged out','Ok'); this._toaster.success(message,'Ok');
}); });
} }
} }
......
...@@ -12,12 +12,12 @@ export class ErrorHandlerService { ...@@ -12,12 +12,12 @@ export class ErrorHandlerService {
public handle(error: number): void { public handle(error: number): void {
if(error === 401) this._handle401Error(error); if(error === 401 || error === 400) this._handle401Error(error);
else if (error === 422) this._handle422Error(error); else if (error === 422) this._handle422Error(error);
} }
private _handle401Error(error: number): void { private _handle401Error(error: number): void {
this._logoutService.logout(); this._logoutService.logout('Session expired !');
} }
private _handle422Error(error: number): void { private _handle422Error(error: number): void {
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpErrorHandlerService } from '../http-error-handler.service';
import { JWTService } from './jwt.service';
import { TransmissionService } from './transmission.service'; import { TransmissionService } from './transmission.service';
import { Auth } from '../../auth/interface/auth'; import { Auth } from '../../auth/interface/auth';
import { RaintreeResponse } from '../interface/raintree-response'; import { RaintreeResponse } from '../interface/raintree-response';
import { UserProfileResponse } from '../interface/user-profile-response'; import { UserProfileResponse } from '../interface/user-profile-response';
import { UserProfile } from '../../auth/interface/user-profile'; import { UserProfile } from '../../auth/interface/user-profile';
import { ErrorHandlerService } from '../error-handler.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AuthTransmissionService extends TransmissionService { export class AuthTransmissionService extends TransmissionService {
constructor(
_http: HttpClient,
_httpErrorHandler: HttpErrorHandlerService,
_jwt: JWTService,
_errorHandler: ErrorHandlerService
) {
super(_http, _httpErrorHandler, _jwt, _errorHandler );
}
public getAuthToken( public getAuthToken(
url: string, url: string,
......
...@@ -5,6 +5,8 @@ import { catchError } from 'rxjs/operators'; ...@@ -5,6 +5,8 @@ import { catchError } from 'rxjs/operators';
import { HttpErrorHandlerService } from '../http-error-handler.service'; import { HttpErrorHandlerService } from '../http-error-handler.service';
import { JWTService } from './jwt.service'; import { JWTService } from './jwt.service';
import { ErrorHandlerService } from '../error-handler.service'; import { ErrorHandlerService } from '../error-handler.service';
import { Router } from '@angular/router';
import { RequestMapperService } from '../../mappers/request-mapper.service';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
...@@ -14,7 +16,7 @@ export class TransmissionService { ...@@ -14,7 +16,7 @@ export class TransmissionService {
private _http: HttpClient, private _http: HttpClient,
private _httpErrorHandler: HttpErrorHandlerService, private _httpErrorHandler: HttpErrorHandlerService,
private _jwt: JWTService, private _jwt: JWTService,
private _errorHandler: ErrorHandlerService private _errorHandler: ErrorHandlerService,
) {} ) {}
public executeBasicGet( public executeBasicGet(
...@@ -108,6 +110,8 @@ export class TransmissionService { ...@@ -108,6 +110,8 @@ export class TransmissionService {
}, },
(error) => { (error) => {
onFailure(error); onFailure(error);
// TODO:handle 401 and 422 error
this._errorHandler.handle(error);
onComplete(); onComplete();
}, },
() => onComplete() () => onComplete()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment