Move service
This commit is contained in:
28
rossa-tech-cli/src/app/auth/pageSecurity.service.ts
Normal file
28
rossa-tech-cli/src/app/auth/pageSecurity.service.ts
Normal file
@@ -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"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user