Skip to content

Commit

Permalink
showing a notification when init failed (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Jan 27, 2023
1 parent 139c58e commit 5197a39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/app/_services/init.service.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -9,7 +9,8 @@ export class InitService {

constructor(private http: HttpClient) { }

fetchInfo(): Observable<{ initialized: boolean }> {
return this.http.get<{ initialized: boolean }>("info");
fetchInfo(): Observable<HttpResponse<{ initialized: boolean }>> {
return this.http.get<{ initialized: boolean }>("info", { observe: "response" });
}

}
24 changes: 17 additions & 7 deletions src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -24,20 +26,28 @@ export class LoginComponent implements OnInit {
private router: Router,
private authenticationService: AuthenticationService,
private initService: InitService,
) { }
private notification: NotificationMessage,
private notificationService: NotificationService,
) {
}

ngOnInit() {
// reset login status
this.authenticationService.logout();

// 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({
Expand Down
4 changes: 4 additions & 0 deletions src/app/notification/notification-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5197a39

Please sign in to comment.