From df599dd7d892e689c1edd421c4894cb610ad7f42 Mon Sep 17 00:00:00 2001 From: Lukas Burgey Date: Mon, 2 Jul 2018 16:17:29 +0200 Subject: [PATCH] Add some types --- src/app/types/types.module.ts | 2 +- src/app/user.service.ts | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/types/types.module.ts b/src/app/types/types.module.ts index 8582d62..f233c4b 100644 --- a/src/app/types/types.module.ts +++ b/src/app/types/types.module.ts @@ -96,7 +96,7 @@ export interface StateAPIResult { user: User; user_state: UserState; services: Service[]; - error: string; + error?: string; } diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 306dfd7..8b02020 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -78,16 +78,18 @@ export class UserService { subscription.map((message: Message) => { return message.body; - }).subscribe((body: any) => { - let json = JSON.parse(body); - if (json.message && json.message != '') { - this.snackBar.open(json.message); - this.messages.push(json.message); - } - if (json.user_state) { - this.updateUserState(json.user_state); + }).subscribe( + (body: any) => { + let json : t.StateAPIResult = JSON.parse(body); + if (json.error && json.error != '') { + this.snackBar.open(json.error); + this.messages.push(json.error); + } + if (json.user_state) { + this.updateUserState(json.user_state); + } } - }); + ); } private updateUser(newUser: t.User) { -- 2.22.2