Skip to content

Commit 38a2f86

Browse files
committed
Dev mode ErrorCard
The `ErrorCard` solved the situation of user-unfriendly error messages, but hid useful information for quickly debugging from QA and customers without having to deal with logs. Expose a way to show the error if dev mode is enabled as a compromise.
1 parent cc6fc96 commit 38a2f86

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/components/cards/ErrorCard.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as React from 'react'
22

33
import { useHandler } from '../../hooks/useHandler'
44
import { lstrings } from '../../locales/strings'
5+
import { useSelector } from '../../types/reactRedux'
6+
import { normalizeError } from '../../util/normalizeError'
57
import { trackError } from '../../util/tracking'
8+
import { RawTextModal } from '../modals/RawTextModal'
9+
import { Airship } from '../services/AirshipInstance'
610
import { AlertCardUi4 } from './AlertCard'
711

812
/**
@@ -29,6 +33,7 @@ interface Props {
2933
export const ErrorCard: React.FC<Props> = props => {
3034
const { error } = props
3135

36+
const isDevMode = useSelector(state => state.ui.settings.developerModeOn)
3237
const [reportSent, setReportSent] = React.useState(false)
3338

3439
const handleReportError = useHandler((): void => {
@@ -47,19 +52,34 @@ export const ErrorCard: React.FC<Props> = props => {
4752
)
4853
}
4954

55+
const buttonProps =
56+
isDevMode || __DEV__
57+
? {
58+
label: 'Show Error',
59+
onPress: async () => {
60+
await Airship.show(bridge => (
61+
<RawTextModal
62+
bridge={bridge}
63+
body={normalizeError(error).toString()}
64+
/>
65+
))
66+
}
67+
}
68+
: {
69+
label: reportSent
70+
? lstrings.string_report_sent
71+
: lstrings.string_report_error,
72+
disabled: reportSent,
73+
onPress: handleReportError
74+
}
75+
5076
// Unhappy path
5177
return (
5278
<AlertCardUi4
5379
type="error"
5480
title={lstrings.error_unexpected_title}
5581
body={lstrings.error_generic_message}
56-
button={{
57-
label: reportSent
58-
? lstrings.string_report_sent
59-
: lstrings.string_report_error,
60-
disabled: reportSent,
61-
onPress: handleReportError
62-
}}
82+
button={buttonProps}
6383
/>
6484
)
6585
}

0 commit comments

Comments
 (0)