From 2c3e2c651df5979c0f7de642a7d5c5f8cf82af2b Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sat, 28 Nov 2020 19:36:19 +0000 Subject: [PATCH 1/2] 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', From 4e5edece48ed6af4f72cb97154ccf51dd489520f Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sat, 28 Nov 2020 19:36:31 +0000 Subject: [PATCH 2/2] Correct HTTP500 error text --- src/app/pages/500.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/500.component.html b/src/app/pages/500.component.html index e09fae4..79ff5ec 100644 --- a/src/app/pages/500.component.html +++ b/src/app/pages/500.component.html @@ -5,7 +5,7 @@

500

Houston, we have a problem!

-

The page you are looking for is temporarily unavailable.

+

Server connection unavailable.