From 2c3e2c651df5979c0f7de642a7d5c5f8cf82af2b Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sat, 28 Nov 2020 19:36:19 +0000 Subject: [PATCH] Add database connection check --- src/app/app.module.ts | 13 ++++++++++++- src/app/providers/api-service.ts | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 067c810..934d439 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -93,7 +93,18 @@ import { FilterPipeModule } from 'ngx-filter-pipe'; bootstrap: [ AppComponent ] }) export class AppModule { - constructor () { + constructor ( + private api: ApiService, + ) { + this.api.checkDatabaseConnection().subscribe( + result => { + }, + error => { + document.location = '#/500'; + throw new Error('Server connection fail'); + } + ); + if (environment.enableAnalytics) { (window).ga('create', environment.analyticsKey, 'auto'); } diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index 8307371..a468ee9 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -42,6 +42,13 @@ export class ApiService { localStorage.removeItem('sessionKey'); } + public checkDatabaseConnection() { + return this.http.post( + this.apiUrl, + null + ); + } + public register(data) { return this.http.post( this.apiUrl + '/register',