From 8c296e93977d303728216bea213174a58516228b Mon Sep 17 00:00:00 2001 From: Patrick Gebhardt Date: Wed, 24 Jun 2020 12:56:47 +0200 Subject: [PATCH] Add http error messages --- .../bookmark-list/bookmark-list.component.html | 6 +++++- .../bookmark-list/bookmark-list.component.ts | 9 ++++++++- frontend/src/app/containers/home/home.component.html | 5 ++++- frontend/src/app/containers/home/home.component.scss | 6 ++++++ frontend/src/app/containers/home/home.component.ts | 12 +++++++++++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/containers/bookmark-list/bookmark-list.component.html b/frontend/src/app/containers/bookmark-list/bookmark-list.component.html index d8f8053..d47f9ec 100644 --- a/frontend/src/app/containers/bookmark-list/bookmark-list.component.html +++ b/frontend/src/app/containers/bookmark-list/bookmark-list.component.html @@ -4,7 +4,11 @@ You have no bookmarks :( -
+
+
+ {{message}} +
+ diff --git a/frontend/src/app/containers/bookmark-list/bookmark-list.component.ts b/frontend/src/app/containers/bookmark-list/bookmark-list.component.ts index bf98639..06c6f09 100644 --- a/frontend/src/app/containers/bookmark-list/bookmark-list.component.ts +++ b/frontend/src/app/containers/bookmark-list/bookmark-list.component.ts @@ -2,9 +2,10 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; import {Region} from '../../interfaces/region.interface'; import {BookmarkService} from '../../services/bookmark.service'; import {DataService} from '../../services/data.service'; -import {switchMap, takeUntil, tap} from 'rxjs/operators'; +import {catchError, switchMap, takeUntil, tap} from 'rxjs/operators'; import {Router} from '@angular/router'; import {Subject} from 'rxjs'; +import {HttpErrorResponse} from '@angular/common/http'; @Component({ selector: 'app-bookmark-list', @@ -15,6 +16,7 @@ export class BookmarkListComponent implements OnInit, OnDestroy { bookmarks: Region[]; isLoading = true; + message: string; private destroyed$ = new Subject(); constructor(private bs: BookmarkService, private ds: DataService, private router: Router) { @@ -27,9 +29,14 @@ export class BookmarkListComponent implements OnInit, OnDestroy { switchMap(ids => { const regions: Promise[] = ids.map(id => this.ds.getRegion(id)); return Promise.all(regions); + }), + catchError((err, caught) => { + this.message = `${(err as HttpErrorResponse).status}: ${(err as HttpErrorResponse).statusText} :/`; + return caught; }) ).subscribe(regions => { this.bookmarks = regions; + this.message = undefined; this.isLoading = false; }); } diff --git a/frontend/src/app/containers/home/home.component.html b/frontend/src/app/containers/home/home.component.html index 8a89191..9be49d5 100644 --- a/frontend/src/app/containers/home/home.component.html +++ b/frontend/src/app/containers/home/home.component.html @@ -1,6 +1,9 @@

Explore the world

-
+
+ No regions to explore :/
+ +{{message}} diff --git a/frontend/src/app/containers/home/home.component.scss b/frontend/src/app/containers/home/home.component.scss index 3a76279..2c1b357 100644 --- a/frontend/src/app/containers/home/home.component.scss +++ b/frontend/src/app/containers/home/home.component.scss @@ -12,8 +12,14 @@ app-search-input { .region-container { display: flex; flex-direction: column; + align-items: center; > app-region { margin-bottom: 2rem; } } + +.central { + align-self: center; + margin: 4rem 0; +} diff --git a/frontend/src/app/containers/home/home.component.ts b/frontend/src/app/containers/home/home.component.ts index 4a5bd16..a24c9b5 100644 --- a/frontend/src/app/containers/home/home.component.ts +++ b/frontend/src/app/containers/home/home.component.ts @@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core'; import {Region} from '../../interfaces/region.interface'; import {DataService} from '../../services/data.service'; import {Router} from '@angular/router'; +import {HttpErrorResponse} from '@angular/common/http'; @Component({ selector: 'app-home', @@ -13,12 +14,21 @@ export class HomeComponent implements OnInit { private readonly MAX_REGIONS = 10; regions: Region[]; + message: string; + loading = true; constructor(private ds: DataService, private router: Router) { } async ngOnInit() { - this.regions = await this.ds.getAllRegions(this.MAX_REGIONS); + try { + this.regions = await this.ds.getAllRegions(this.MAX_REGIONS); + } catch (e) { + this.message = `${(e as HttpErrorResponse).status}: ${(e as HttpErrorResponse).statusText} :/`; + } finally { + this.loading = false; + } + } onRegionClick(region: Region) {