| | |
| | | import { of } from 'rxjs/observable/of'; |
| | | import { ErrorObservable } from 'rxjs/observable/ErrorObservable'; |
| | | import { mergeMap, catchError } from 'rxjs/operators'; |
| | | import { NzMessageService } from 'ng-zorro-antd'; |
| | | import { NzMessageService, NzModalService } from 'ng-zorro-antd'; |
| | | import { _HttpClient } from '@delon/theme'; |
| | | import { environment } from '@env/environment'; |
| | | import { LoginService } from '@business/services/http/login.service'; |
| | | import { Subject } from 'rxjs/Subject'; |
| | | import { error } from 'protractor'; |
| | | import { debug } from 'util'; |
| | | |
| | | /** |
| | | * 默认HTTP拦截器,其注册细节见 `app.module.ts` |
| | | */ |
| | | @Injectable() |
| | | export class DefaultInterceptor implements HttpInterceptor { |
| | | constructor(private injector: Injector) {} |
| | | private unLoginHandle: Subject<HttpErrorResponse> = new Subject<HttpErrorResponse>(); |
| | | constructor(private injector: Injector) { |
| | | this.unLoginHandle.debounceTime(100).subscribe(event => { |
| | | if (!!event.error) { |
| | | let errorMsg = ''; |
| | | const erroCode = <number>event.error['errorCode']; |
| | | switch (erroCode) { |
| | | case 10: errorMsg = '未登录,请登录'; break; |
| | | case 11: errorMsg = '登录过期,请重新登录'; break; |
| | | case 12: errorMsg = '账号过期,请联系供应商'; break; |
| | | } |
| | | this.model.info({ |
| | | title: errorMsg, |
| | | onOk: () => this.goTo('/passport/login') |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | get msg(): NzMessageService { |
| | | return this.injector.get(NzMessageService); |
| | | } |
| | | |
| | | get model(): NzModalService { |
| | | return this.injector.get(NzModalService); |
| | | } |
| | | private goTo(url: string) { |
| | | setTimeout(() => this.injector.get(Router).navigateByUrl(url)); |
| | | } |
| | |
| | | // } |
| | | break; |
| | | case 401: // 未登录状态码 |
| | | this.goTo('/passport/login'); |
| | | // this.goTo('/passport/login'); |
| | | this.unLoginHandle.next(<HttpErrorResponse>event); |
| | | break; |
| | | case 403: |
| | | case 404: |