fix(token): token signature error

This commit is contained in:
禾几海
2020-08-28 09:36:21 +08:00
parent 32e5c4daf0
commit 58655bed94
3 changed files with 20 additions and 12 deletions

View File

@@ -62,14 +62,14 @@ export class HttpService {
} }
if (o.body.code !== 0) { if (o.body.code !== 0) {
observer.error(o.body); observer.error(o.body);
errorService.httpException(o.body) errorService.httpException(o.body, request)
} else { } else {
observer.next(o.body); observer.next(o.body);
} }
observer.complete(); observer.complete();
}, },
error: err => { error: err => {
errorService.httpError(err); errorService.httpError(err,request);
errorService.checkConnection(); errorService.checkConnection();
this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1) this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
}, },

View File

@@ -1,40 +1,48 @@
import {Injectable} from '@angular/core'; import {Injectable, Injector} from '@angular/core';
import {RequestObj, Response} from '../class/HttpReqAndResp'; import {RequestObj, Response} from '../class/HttpReqAndResp';
import {HttpService} from '../api/http/http.service';
import {environment} from '../../environments/environment'; import {environment} from '../../environments/environment';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {ComponentStateService} from './component-state.service'; import {ComponentStateService} from './component-state.service';
import {NzNotificationService} from 'ng-zorro-antd'; import {NzNotificationService} from 'ng-zorro-antd';
import {HttpService} from '../api/http/http.service';
import {LocalStorageService} from './local-storage.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class ErrorService { export class ErrorService {
constructor(private httpService: HttpService, private router: Router, constructor(/*private httpService: HttpService,*/
private router: Router,
private injector: Injector,
private componentStateService: ComponentStateService, private componentStateService: ComponentStateService,
private notification: NzNotificationService) { private notification: NzNotificationService,
private localStorageService: LocalStorageService) {
} }
private static HTTP_ERROR_COUNT: number = 0; private static HTTP_ERROR_COUNT: number = 0;
private readonly MAINTAIN_PAGE_PREFIX = '/maintain' private readonly MAINTAIN_PAGE_PREFIX = '/maintain'
private readonly ADMIN_PAGE_PREFIX = '/admin' private readonly ADMIN_PAGE_PREFIX = '/admin'
public httpError(err: any) { public httpError(err: any, request: RequestObj) {
if (!environment.production) { if (!environment.production) {
console.log('error=>', err) console.log('error=>', err, request)
} }
ErrorService.HTTP_ERROR_COUNT++; ErrorService.HTTP_ERROR_COUNT++;
// this.httpService.getSubscriptionQueue().map(a => a.unsubscribe()) // this.httpService.getSubscriptionQueue().map(a => a.unsubscribe())
} }
public httpException(response: Response<any>) { public httpException(response: Response<any>, request: RequestObj) {
if (!environment.production) if (!environment.production)
console.log('exception=>', response) console.log('exception=>', response, request)
if (response.code === -1 && response.msg === '重复请求') return if (response.code === -1 && response.msg === '重复请求') return
if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) { if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) {
this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`); this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`);
} }
// 3830 token签名错误
if (response.code === 3830) {
this.localStorageService.removeToken();
}
} }
public checkConnection() { public checkConnection() {
@@ -45,7 +53,7 @@ export class ErrorService {
method: 'GET', method: 'GET',
url: environment.host + '/headerInfo' url: environment.host + '/headerInfo'
} }
this.httpService.get(req).subscribe({ this.injector.get(HttpService).get(req).subscribe({
next: () => null, next: () => null,
error: () => { error: () => {
if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) { if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) {

View File

@@ -5,7 +5,7 @@
export const environment = { export const environment = {
production: false, production: false,
logger: true, logger: true,
host: 'http://celess.cn:8082/' host: 'http://127.0.0.1/'
}; };
/* /*