From 5197a39bc82ccee270ff691d7f937d6c895806ac Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Fri, 27 Jan 2023 10:57:19 +0100 Subject: [PATCH] showing a notification when init failed (#305) --- src/app/_services/init.service.ts | 7 +++--- src/app/login/login.component.ts | 24 +++++++++++++------ src/app/notification/notification-messages.ts | 4 ++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/app/_services/init.service.ts b/src/app/_services/init.service.ts index 7c00b006..e88a5435 100644 --- a/src/app/_services/init.service.ts +++ b/src/app/_services/init.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from "@angular/common/http"; +import { HttpClient, HttpResponse } from "@angular/common/http"; import { Injectable } from "@angular/core"; import { Observable } from "rxjs"; @@ -9,7 +9,8 @@ export class InitService { constructor(private http: HttpClient) { } - fetchInfo(): Observable<{ initialized: boolean }> { - return this.http.get<{ initialized: boolean }>("info"); + fetchInfo(): Observable> { + return this.http.get<{ initialized: boolean }>("info", { observe: "response" }); } + } diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index c46cffe7..f35fde3b 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -4,6 +4,8 @@ import { ActivatedRoute, Router } from "@angular/router"; import { AuthenticationService } from "../_services/authentication.service"; import { first } from "rxjs/operators"; import { InitService } from "../_services/init.service"; +import { NotificationService } from "../_services/notification.service"; +import { NotificationMessage } from "../notification/notification-messages"; @Component({ selector: "app-login", @@ -24,7 +26,10 @@ export class LoginComponent implements OnInit { private router: Router, private authenticationService: AuthenticationService, private initService: InitService, - ) { } + private notification: NotificationMessage, + private notificationService: NotificationService, + ) { + } ngOnInit() { // reset login status @@ -32,12 +37,17 @@ export class LoginComponent implements OnInit { // slow down to give top panel time to disappear new Promise(resolve => setTimeout(resolve, 0)).then(); - this.initService.fetchInfo().subscribe((res) => { - if (res.initialized === false) { - this.router.navigate(["init"]); - } - this.initLoaded = true; - }); + this.initService.fetchInfo() + .subscribe((res) => { + if (res?.body?.initialized === false) { + this.router.navigate(["init"]); + } + this.initLoaded = true; + }, (res) => { + const message = this.notification.appInitialization(res); + this.notificationService.showNotification(message); + + }); this.loginForm = this.formBuilder.group({ diff --git a/src/app/notification/notification-messages.ts b/src/app/notification/notification-messages.ts index c4b2a8cf..59230713 100644 --- a/src/app/notification/notification-messages.ts +++ b/src/app/notification/notification-messages.ts @@ -82,6 +82,10 @@ export class NotificationMessage { return this.statusCodeMessage(response, "Thresholds were updated"); } + appInitialization(response) { + return this.statusCodeMessage(response, "") + } + private statusCodeMessage(response, successMessage) { let message = { success: false, message: (typeof response === "string" && response?.includes("Unexpected error")) ? response : "Unexpected error occurred" }; if (response.status >= 200 && response.status < 300) {