La disponibilité du serveur vérifie également pour l'erreur 502
This commit is contained in:
parent
2d8a1ac0e0
commit
8457c1aa75
|
@ -1,11 +1,11 @@
|
|||
import {Injectable, OnDestroy} from '@angular/core';
|
||||
import {Subject} from "rxjs";
|
||||
import {take, takeUntil} from "rxjs/operators";
|
||||
import {AppState} from "../../shared/app-state";
|
||||
import {HttpClient, HttpResponse} from "@angular/common/http";
|
||||
import {environment} from "../../../../environments/environment";
|
||||
import {ApiService} from "../../shared/service/api.service";
|
||||
import {Employee, EmployeePermission} from "../../shared/model/employee";
|
||||
import {Injectable, OnDestroy} from '@angular/core'
|
||||
import {Subject} from 'rxjs'
|
||||
import {take, takeUntil} from 'rxjs/operators'
|
||||
import {AppState} from '../../shared/app-state'
|
||||
import {HttpClient, HttpResponse} from '@angular/common/http'
|
||||
import {environment} from '../../../../environments/environment'
|
||||
import {ApiService} from '../../shared/service/api.service'
|
||||
import {Employee, EmployeePermission} from '../../shared/model/employee'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -39,7 +39,7 @@ export class AccountService implements OnDestroy {
|
|||
).subscribe({
|
||||
next: employee => this.appState.authenticatedEmployee = employee,
|
||||
error: err => {
|
||||
if (err.status === 0 && err.statusText === "Unknown Error") {
|
||||
if (err.status === 0 && err.statusText === 'Unknown Error' || err.status === 502) {
|
||||
this.appState.isServerOnline = false
|
||||
} else {
|
||||
this.appState.isServerOnline = true
|
||||
|
@ -67,13 +67,13 @@ export class AccountService implements OnDestroy {
|
|||
)
|
||||
.subscribe({
|
||||
next: (response: HttpResponse<any>) => {
|
||||
this.appState.authenticationExpiration = parseInt(response.headers.get("X-Authentication-Expiration"))
|
||||
this.appState.authenticationExpiration = parseInt(response.headers.get('X-Authentication-Expiration'))
|
||||
this.appState.isAuthenticated = true
|
||||
this.setLoggedInEmployeeFromApi()
|
||||
success()
|
||||
},
|
||||
error: err => {
|
||||
if (err.status === 0 && err.statusText === "Unknown Error") {
|
||||
if (err.status === 0 && err.statusText === 'Unknown Error' || err.status === 502) {
|
||||
this.appState.isServerOnline = false
|
||||
} else {
|
||||
this.appState.isServerOnline = true
|
||||
|
@ -105,7 +105,7 @@ export class AccountService implements OnDestroy {
|
|||
}
|
||||
|
||||
private setLoggedInEmployeeFromApi() {
|
||||
this.api.get<Employee>("/employee/current", true)
|
||||
this.api.get<Employee>('/employee/current', true)
|
||||
.pipe(
|
||||
take(1),
|
||||
takeUntil(this.destroy$)
|
||||
|
@ -113,7 +113,7 @@ export class AccountService implements OnDestroy {
|
|||
.subscribe({
|
||||
next: employee => this.appState.authenticatedEmployee = employee,
|
||||
error: err => {
|
||||
console.error("Could not get the logged in employee from the API: ")
|
||||
console.error('Could not get the logged in employee from the API: ')
|
||||
console.error(err)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {Injectable, OnDestroy} from '@angular/core';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {Observable, Subject} from "rxjs";
|
||||
import {environment} from "../../../../environments/environment";
|
||||
import {AppState} from "../app-state";
|
||||
import {Router} from "@angular/router";
|
||||
import {map, share, takeUntil} from "rxjs/operators";
|
||||
import {valueOr} from "../utils/optional.utils";
|
||||
import {Injectable, OnDestroy} from '@angular/core'
|
||||
import {HttpClient} from '@angular/common/http'
|
||||
import {Observable, Subject} from 'rxjs'
|
||||
import {environment} from '../../../../environments/environment'
|
||||
import {AppState} from '../app-state'
|
||||
import {Router} from '@angular/router'
|
||||
import {map, share, takeUntil} from 'rxjs/operators'
|
||||
import {valueOr} from '../utils/optional.utils'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -72,7 +72,7 @@ export class ApiService implements OnDestroy {
|
|||
if (httpOptions) {
|
||||
httpOptions.withCredentials = true
|
||||
} else {
|
||||
console.error("httpOptions need to be specified to use credentials in HTTP methods.")
|
||||
console.error('httpOptions need to be specified to use credentials in HTTP methods.')
|
||||
}
|
||||
} else {
|
||||
this.navigateToLogin()
|
||||
|
@ -90,7 +90,7 @@ export class ApiService implements OnDestroy {
|
|||
error: err => {
|
||||
console.error(err)
|
||||
errorCheckSubscription.unsubscribe()
|
||||
this.appState.isServerOnline = !(err.status === 0 && err.statusText === "Unknown Error");
|
||||
this.appState.isServerOnline = !(err.status === 0 && err.statusText === 'Unknown Error' || err.status === 502)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue