Write error to log on promise rejected

This commit is contained in:
Jerko Steiner 2020-03-10 09:03:11 +01:00
parent 18ff3947b8
commit 2f582e66b9
3 changed files with 24 additions and 3 deletions

View File

@ -14,6 +14,15 @@ export type RejectedAction<T extends string> = Action<T> & {
status: 'rejected'
}
export function isRejectedAction(
value: unknown,
): value is RejectedAction<string> {
// 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<T extends string, P> =
PendingAction<T, P> |
ResolvedAction<T, P> |

View File

@ -123,7 +123,7 @@ extends React.PureComponent<ToolbarProps, ToolbarState> {
if (this.props.desktopStream) {
this.props.onRemoveStream(ME_DESKTOP)
} else {
this.props.onGetDesktopStream()
this.props.onGetDesktopStream().catch(() => {})
}
}
render () {

View File

@ -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<string, Notification>
@ -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: