From d9feca65c1349cf41ed9654cd4b0cb4381bc465d Mon Sep 17 00:00:00 2001 From: Peter Rossa Date: Mon, 15 May 2023 12:51:32 +0200 Subject: [PATCH] Move service --- .../src/app/auth/pageSecurity.service.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 rossa-tech-cli/src/app/auth/pageSecurity.service.ts diff --git a/rossa-tech-cli/src/app/auth/pageSecurity.service.ts b/rossa-tech-cli/src/app/auth/pageSecurity.service.ts new file mode 100644 index 0000000..7b080e5 --- /dev/null +++ b/rossa-tech-cli/src/app/auth/pageSecurity.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from "@angular/core"; +import { Router } from "@angular/router"; +import { HttpErrorResponse } from "@angular/common/http"; + +@Injectable({ + providedIn: "root", +}) +export class PageSecurityService { + constructor(private router: Router) {} + + public gotoLoginPage() { + this.router.navigate(["/login"]); + } + + public checkPageSecurityError(httpError: HttpErrorResponse) { + if (!httpError || httpError.status == null) { + throw new Error("Invalid http error object."); + } + + if (httpError.status === 401) { + this.gotoLoginPage(); + } + + if (httpError.status === 403) { + this.router.navigate(["/accessDenied"]); + } + } +}