Commit 8d3b1759 authored by achinta's avatar achinta

feat: handel error

parent ba26db00
......@@ -20,7 +20,7 @@ export class LogoutService {
}
public logout(): void {
public logout(message:string = 'Successfully Logged out'): void {
if (this.isBrowser) {
......@@ -30,7 +30,7 @@ export class LogoutService {
this._router.navigate([RequestMapperService.LOGIN_URL]).then(() => {
// window.location.reload();
this._toaster.success('Successfully Logged out','Ok');
this._toaster.success(message,'Ok');
});
}
}
......
......@@ -12,12 +12,12 @@ export class ErrorHandlerService {
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);
}
private _handle401Error(error: number): void {
this._logoutService.logout();
this._logoutService.logout('Session expired !');
}
private _handle422Error(error: number): void {
......
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpErrorHandlerService } from '../http-error-handler.service';
import { JWTService } from './jwt.service';
import { TransmissionService } from './transmission.service';
import { Auth } from '../../auth/interface/auth';
import { RaintreeResponse } from '../interface/raintree-response';
import { UserProfileResponse } from '../interface/user-profile-response';
import { UserProfile } from '../../auth/interface/user-profile';
import { ErrorHandlerService } from '../error-handler.service';
@Injectable({
providedIn: 'root'
})
export class AuthTransmissionService extends TransmissionService {
constructor(
_http: HttpClient,
_httpErrorHandler: HttpErrorHandlerService,
_jwt: JWTService,
_errorHandler: ErrorHandlerService
) {
super(_http, _httpErrorHandler, _jwt, _errorHandler );
}
public getAuthToken(
url: string,
......
......@@ -5,6 +5,8 @@ import { catchError } from 'rxjs/operators';
import { HttpErrorHandlerService } from '../http-error-handler.service';
import { JWTService } from './jwt.service';
import { ErrorHandlerService } from '../error-handler.service';
import { Router } from '@angular/router';
import { RequestMapperService } from '../../mappers/request-mapper.service';
@Injectable({
providedIn: 'root',
......@@ -14,7 +16,7 @@ export class TransmissionService {
private _http: HttpClient,
private _httpErrorHandler: HttpErrorHandlerService,
private _jwt: JWTService,
private _errorHandler: ErrorHandlerService
private _errorHandler: ErrorHandlerService,
) {}
public executeBasicGet(
......@@ -108,6 +110,8 @@ export class TransmissionService {
},
(error) => {
onFailure(error);
// TODO:handle 401 and 422 error
this._errorHandler.handle(error);
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