Merge branch '5-ajout-d-un-check-pour-une-erreur-502-lors-de-la-verification-de-la-disponibilite-du-backend' into 'master'

Resolve "Ajout d'un check pour une erreur 502 lors de la vérification de la disponibilité du backend."

Closes #5

See merge request color-recipes-explorer/frontend!2
This commit is contained in:
William Nolin 2021-02-15 04:02:23 +00:00
commit 3f885e9e02
2 changed files with 23 additions and 23 deletions

View File

@ -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)
}
})

View File

@ -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)
}
})