diff --git a/src/app/modules/accounts/services/account.service.ts b/src/app/modules/accounts/services/account.service.ts index 8284354..c59dd0d 100644 --- a/src/app/modules/accounts/services/account.service.ts +++ b/src/app/modules/accounts/services/account.service.ts @@ -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) => { - 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/current", true) + this.api.get('/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) } }) diff --git a/src/app/modules/shared/service/api.service.ts b/src/app/modules/shared/service/api.service.ts index eec4707..fa714b2 100644 --- a/src/app/modules/shared/service/api.service.ts +++ b/src/app/modules/shared/service/api.service.ts @@ -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) } })