seimin 2 lat temu
rodzic
commit
13b980e584
1 zmienionych plików z 8 dodań i 1 usunięć
  1. 8 1
      src/app/services/httpInterceptor.service.ts

+ 8 - 1
src/app/services/httpInterceptor.service.ts

@@ -7,9 +7,11 @@ import {
7 7
 } from "@angular/common/http";
8 8
 import { Observable } from "rxjs";
9 9
 import { tap } from "rxjs/operators";
10
+import { Router } from '@angular/router';
11
+import { NzMessageService } from 'ng-zorro-antd';
10 12
 // const ignoreToken = ['login', 'logout', 'table'];
11 13
 export class HttpInterceptorService implements HttpInterceptor {
12
-  constructor() {}
14
+  constructor(private router: Router, private message: NzMessageService) {}
13 15
   intercept(
14 16
     req: HttpRequest<any>,
15 17
     next: HttpHandler
@@ -32,6 +34,11 @@ export class HttpInterceptorService implements HttpInterceptor {
32 34
         (event) => {
33 35
           if (event instanceof HttpResponse) {
34 36
             // console.log(event);
37
+            if(event.body == 520){
38
+              this.message.info('登录失效,请重新登录!').onClose!.subscribe(() => {
39
+                this.router.navigate(['/login']);
40
+              })
41
+            }
35 42
           }
36 43
         },
37 44
         (error) => {