import { Injectable } from '@angular/core'; import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor, HttpErrorResponse, } from '@angular/common/http'; import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { EmopUtilsService } from '../services/emop-utils.service'; @Injectable() export class EMOPHTTPInterceptor implements HttpInterceptor { constructor( private emop: EmopUtilsService ) { } intercept(request: HttpRequest, next: HttpHandler): Observable> { return next.handle(request).pipe( catchError((err: HttpErrorResponse) => { if (err.status === 401) { this.emop.notice('info', '权限校验失效', '用户token失效,请重新登录'); setTimeout(() => { window.location.href = '/gateway/static/index.html#/login'; }, 1500); } else { this.emop.notice('error', '操作失败', err.error.message || err.error.error); } throw err; }) ); } }