diff --git a/dmp-frontend/src/app/common/http/common-http.module.ts b/dmp-frontend/src/app/common/http/common-http.module.ts index e1d4a1521..35f48be43 100644 --- a/dmp-frontend/src/app/common/http/common-http.module.ts +++ b/dmp-frontend/src/app/common/http/common-http.module.ts @@ -7,6 +7,7 @@ import { ProgressIndicationInterceptor } from './interceptors/progress-indicatio import { RequestTimingInterceptor } from './interceptors/request-timing.interceptor'; import { ResponsePayloadInterceptor } from './interceptors/response-payload.interceptor'; import { UnauthorizedResponseInterceptor } from './interceptors/unauthorized-response.interceptor'; +import { StatusCodeInterceptor } from './interceptors/status-code.interceptor'; @NgModule({ imports: [ @@ -48,6 +49,11 @@ import { UnauthorizedResponseInterceptor } from './interceptors/unauthorized-res provide: HTTP_INTERCEPTORS, useClass: ResponsePayloadInterceptor, multi: true, + }, + { + provide: HTTP_INTERCEPTORS, + useClass: StatusCodeInterceptor, + multi: true, } ] }) diff --git a/dmp-frontend/src/app/common/http/interceptors/interceptor-type.ts b/dmp-frontend/src/app/common/http/interceptors/interceptor-type.ts index bba2dea1c..d0dcf9938 100644 --- a/dmp-frontend/src/app/common/http/interceptors/interceptor-type.ts +++ b/dmp-frontend/src/app/common/http/interceptors/interceptor-type.ts @@ -6,4 +6,5 @@ export enum InterceptorType { RequestTiming = 4, UnauthorizedResponse = 5, ResponsePayload = 5, + StatusCode = 6 } diff --git a/dmp-frontend/src/app/common/http/interceptors/status-code.interceptor.ts b/dmp-frontend/src/app/common/http/interceptors/status-code.interceptor.ts new file mode 100644 index 000000000..78a4aa331 --- /dev/null +++ b/dmp-frontend/src/app/common/http/interceptors/status-code.interceptor.ts @@ -0,0 +1,23 @@ +import { Injectable } from "@angular/core"; +import { BaseInterceptor } from "./base.interceptor"; +import { InterceptorType } from "./interceptor-type"; +import { HttpHandler, HttpRequest, HttpEvent } from "@angular/common/http"; +import { Observable } from "rxjs"; +import { Router } from "@angular/router"; + +@Injectable() +export class StatusCodeInterceptor extends BaseInterceptor { + + type: InterceptorType; + interceptRequest(req: HttpRequest, next: HttpHandler): Observable> { + return next.handle(req).do(event => { }, err => { + if (err.status === 480) { + this.router.navigate(['confirmation']); + } + }); + } + + constructor( + private router: Router, + ) { super(); } +}