From 53ddfe6e4c932dbb5af055aeaecd0626ea3f3582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Wed, 5 Aug 2020 22:30:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/services/error.service.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/services/error.service.ts b/src/app/services/error.service.ts index b68b35a..a1a00f6 100644 --- a/src/app/services/error.service.ts +++ b/src/app/services/error.service.ts @@ -4,6 +4,7 @@ import {HttpService} from '../api/http/http.service'; import {environment} from '../../environments/environment'; import {Router} from '@angular/router'; import {ComponentStateService} from './component-state.service'; +import {NzNotificationService} from 'ng-zorro-antd'; @Injectable({ providedIn: 'root' @@ -11,11 +12,13 @@ import {ComponentStateService} from './component-state.service'; export class ErrorService { constructor(private httpService: HttpService, private router: Router, - private componentStateService: ComponentStateService) { + private componentStateService: ComponentStateService, + private notification: NzNotificationService) { } private static HTTP_ERROR_COUNT: number = 0; private readonly MAINTAIN_PAGE_PREFIX = '/maintain' + private readonly ADMIN_PAGE_PREFIX = '/admin' public httpError(err: any) { if (!environment.production) { @@ -28,6 +31,10 @@ export class ErrorService { public httpException(response: Response) { if (!environment.production) console.log('exception=>', response) + if (response.code === -1 && response.msg === '请求重复') return + if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) { + this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`); + } } public checkConnection() { @@ -39,8 +46,8 @@ export class ErrorService { url: environment.host + '/headerInfo' } this.httpService.get(req).subscribe({ - next: data => null, - error: err => { + next: () => null, + error: () => { if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) { this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX) }