From 2f582e66b9a3b454a7dc22a4eb6f82315678b95c Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Tue, 10 Mar 2020 09:03:11 +0100 Subject: [PATCH] Write error to log on promise rejected --- src/client/async/action.ts | 9 +++++++++ src/client/components/Toolbar.tsx | 2 +- src/client/reducers/notifications.ts | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/client/async/action.ts b/src/client/async/action.ts index 8f3ffbc..1c91575 100644 --- a/src/client/async/action.ts +++ b/src/client/async/action.ts @@ -14,6 +14,15 @@ export type RejectedAction = Action & { status: 'rejected' } +export function isRejectedAction( + value: unknown, +): value is RejectedAction { + // eslint-disable-next-line + const v = value as any + return !!v && 'type' in v && typeof v.type === 'string' && + 'status' in v && v.status === 'rejected' +} + export type AsyncAction = PendingAction | ResolvedAction | diff --git a/src/client/components/Toolbar.tsx b/src/client/components/Toolbar.tsx index ce54482..63299b8 100644 --- a/src/client/components/Toolbar.tsx +++ b/src/client/components/Toolbar.tsx @@ -123,7 +123,7 @@ extends React.PureComponent { if (this.props.desktopStream) { this.props.onRemoveStream(ME_DESKTOP) } else { - this.props.onGetDesktopStream() + this.props.onGetDesktopStream().catch(() => {}) } } render () { diff --git a/src/client/reducers/notifications.ts b/src/client/reducers/notifications.ts index 3679d38..d68d58b 100644 --- a/src/client/reducers/notifications.ts +++ b/src/client/reducers/notifications.ts @@ -1,5 +1,7 @@ import * as constants from '../constants' -import { Notification, NotificationActionType } from '../actions/NotifyActions' +import { error, Notification, NotificationActionType } from '../actions/NotifyActions' +import { isRejectedAction } from '../async' +import { AnyAction } from 'redux' export type NotificationState = Record @@ -7,7 +9,17 @@ const defaultState: NotificationState = {} export default function notifications ( state = defaultState, - action: NotificationActionType, + action: AnyAction, +) { + if (isRejectedAction(action)) { + action = error(action.payload) + } + return handleNotifications(state, action) +} + +function handleNotifications ( + state = defaultState, + action: NotificationActionType, ) { switch (action.type) { case constants.NOTIFY: