Commit 0a0b4632 authored by wangqinghua's avatar wangqinghua

error message提示

parent d7c91faf
......@@ -31,6 +31,7 @@ import {route} from './app.route';
import {LoginGuard} from './shared/common/loginGuard';
import {AppMainModule} from './app.main.module';
import {AppService} from './app.service';
import {NzMessageService, NzNotificationService} from 'ng-zorro-antd';
@NgModule({
imports: [
......@@ -67,7 +68,8 @@ import {AppService} from './app.service';
multi: true,
deps: [
LocalStorageService,
SessionStorageService
SessionStorageService,
NzMessageService,
]
},
{
......@@ -83,7 +85,9 @@ import {AppService} from './app.service';
useClass: ErrorHandlerInterceptor,
multi: true,
deps: [
JhiEventManager
JhiEventManager,
NzMessageService,
NzNotificationService,
]
},
{
......
......@@ -3,13 +3,14 @@ import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { SERVER_API_URL } from '../../app.constants';
import {ActivatedRoute, Router} from "@angular/router";
import {NzMessageService} from 'ng-zorro-antd';
export class AuthInterceptor implements HttpInterceptor {
constructor(
private localStorage: LocalStorageService,
private sessionStorage: SessionStorageService,
public router: Router,
public router: Router,private message:NzMessageService,
) {
}
......
import { JhiEventManager } from 'ng-jhipster';
import { HttpInterceptor, HttpRequest, HttpErrorResponse, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import {JhiEventManager} from 'ng-jhipster';
import {HttpInterceptor, HttpRequest, HttpErrorResponse, HttpHandler, HttpEvent} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import {NzMessageService, NzNotificationService} from 'ng-zorro-antd';
export class ErrorHandlerInterceptor implements HttpInterceptor {
constructor(private eventManager: JhiEventManager) {
constructor(private eventManager: JhiEventManager, private message: NzMessageService,
public notification: NzNotificationService) {
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).do((event: HttpEvent<any>) => {}, (err: any) => {
return next.handle(request).do((event: HttpEvent<any>) => {
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (!(err.status === 401 && (err.message === '' || (err.url && err.url.indexOf('/api/account') === 0)))) {
if (this.eventManager !== undefined) {
this.eventManager.broadcast({name: 'bootappApp.httpError', content: err});
this.messageInfo(err);
}
});
}
messageInfo(err) {
const status = err.status;
switch (status) {
case 401:
this.notification.create('error', '错误', '登录信息已过期', {nzDuration: 2000});
break;
case 404:
this.notification.create('error', '错误', `${err.url}不存在`, {nzDuration: 2000});
break;
case 500:
this.notification.create('error', '错误', `${err.message}`, {nzDuration: 2000});
break;
}
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment