路由跳转
This commit is contained in:
@@ -12,7 +12,7 @@ import {ErrorService} from '../../services/error.service';
|
|||||||
export class HttpService {
|
export class HttpService {
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient,
|
constructor(private httpClient: HttpClient,
|
||||||
protected localStorageService: LocalStorageService,
|
private localStorageService: LocalStorageService,
|
||||||
private injector: Injector) {
|
private injector: Injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,6 +70,7 @@ export class HttpService {
|
|||||||
},
|
},
|
||||||
error: err => {
|
error: err => {
|
||||||
errorService.httpError(err);
|
errorService.httpError(err);
|
||||||
|
errorService.checkConnection();
|
||||||
this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
|
this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
|
||||||
},
|
},
|
||||||
complete: () => this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
|
complete: () => this.subscriptionQueue.splice(this.subscriptionQueue.indexOf(subscription), 1)
|
||||||
@@ -78,7 +79,7 @@ export class HttpService {
|
|||||||
return oob;
|
return oob;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get<T>(request: RequestObj) {
|
get<T>(request: RequestObj) {
|
||||||
return this.httpClient.get<T>(request.url,
|
return this.httpClient.get<T>(request.url,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
@@ -87,7 +88,7 @@ export class HttpService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private post<T>(request: RequestObj) {
|
post<T>(request: RequestObj) {
|
||||||
return this.httpClient.post<T>(request.url, request.data,
|
return this.httpClient.post<T>(request.url, request.data,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
@@ -96,7 +97,7 @@ export class HttpService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private put<T>(request: RequestObj) {
|
put<T>(request: RequestObj) {
|
||||||
return this.httpClient.put<T>(request.url, request.data,
|
return this.httpClient.put<T>(request.url, request.data,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
@@ -105,7 +106,7 @@ export class HttpService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private delete<T>(request: RequestObj) {
|
delete<T>(request: RequestObj) {
|
||||||
return this.httpClient.delete<T>(request.url,
|
return this.httpClient.delete<T>(request.url,
|
||||||
{
|
{
|
||||||
headers: request.header,
|
headers: request.header,
|
||||||
|
|||||||
@@ -1,23 +1,52 @@
|
|||||||
import {Injectable, Injector} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Response} from '../class/HttpReqAndResp';
|
import {RequestObj, Response} from '../class/HttpReqAndResp';
|
||||||
import {HttpService} from '../api/http/http.service';
|
import {HttpService} from '../api/http/http.service';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
import {Router} from '@angular/router';
|
||||||
|
import {ComponentStateService} from './component-state.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ErrorService {
|
export class ErrorService {
|
||||||
|
|
||||||
constructor(private httpService: HttpService) {
|
constructor(private httpService: HttpService, private router: Router,
|
||||||
|
private componentStateService: ComponentStateService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static HTTP_ERROR_COUNT: number = 0;
|
||||||
|
private readonly MAINTAIN_PAGE_PREFIX = '/maintain'
|
||||||
|
|
||||||
public httpError(err: any) {
|
public httpError(err: any) {
|
||||||
console.log('error=>', err)
|
if (!environment.production) {
|
||||||
|
console.log('error=>', err)
|
||||||
|
}
|
||||||
|
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>) {
|
||||||
console.log('exception=>', response)
|
if (!environment.production)
|
||||||
|
console.log('exception=>', response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public checkConnection() {
|
||||||
|
// The HTTP_ERROR_COUNT is start with 1 in this function
|
||||||
|
if (ErrorService.HTTP_ERROR_COUNT === 1) {
|
||||||
|
const req: RequestObj = {
|
||||||
|
path: '/headerInfo',
|
||||||
|
method: 'GET',
|
||||||
|
url: environment.host + '/headerInfo'
|
||||||
|
}
|
||||||
|
this.httpService.get(req).subscribe({
|
||||||
|
next: data => null,
|
||||||
|
error: err => {
|
||||||
|
if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) {
|
||||||
|
this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX)
|
||||||
|
}
|
||||||
|
ErrorService.HTTP_ERROR_COUNT = 0;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user