Gaëtan Renaudeau
7 years ago
25 changed files with 162 additions and 69 deletions
@ -0,0 +1,25 @@ |
|||
// @flow
|
|||
// Convention:
|
|||
// - errors we throw on our app will use a different error.name per error type
|
|||
// - an error can have parameters, to use them, just use field of the Error object, that's what we give to `t()`
|
|||
// - returned value is intentially not styled (is universal). wrap this in whatever you need
|
|||
|
|||
import { PureComponent } from 'react' |
|||
import { translate } from 'react-i18next' |
|||
import type { T } from 'types/common' |
|||
|
|||
type Props = { |
|||
error: ?Error, |
|||
t: T, |
|||
} |
|||
|
|||
class TranslatedError extends PureComponent<Props> { |
|||
render() { |
|||
const { t, error } = this.props |
|||
if (!error) return null |
|||
if (typeof error === 'string') return error |
|||
return t(`errors:${error.name}`, error) |
|||
} |
|||
} |
|||
|
|||
export default translate()(TranslatedError) |
@ -0,0 +1,13 @@ |
|||
// @flow
|
|||
|
|||
export default (name: string) => { |
|||
const C = function CustomError(message?: string, fields?: Object) { |
|||
this.name = name |
|||
this.message = message || name |
|||
this.stack = new Error().stack |
|||
Object.assign(this, fields) |
|||
} |
|||
// $FlowFixMe
|
|||
C.prototype = new Error() |
|||
return C |
|||
} |
@ -0,0 +1,13 @@ |
|||
RangeError: {{message}} |
|||
Error: {{message}} |
|||
LedgerAPIErrorWithMessage: {{message}} |
|||
TransportStatusError: {{message}} |
|||
FeeEstimationFailed: 'fee estimation failed (status: {{status}})' |
|||
NotEnoughBalance: 'Not enough balance' |
|||
BtcUnmatchedApp: 'You must open application ‘{{currencyName}}’ on the device' |
|||
WrongAppOpened: 'You must open application ‘{{currencyName}}’ on the device' |
|||
WrongDeviceForAccount: 'You must use the device associated to the account ‘{{accountName}}’' |
|||
LedgerAPINotAvailable: 'Ledger API is not available for currency {{currencyName}}' |
|||
LedgerAPIError: 'A problem occurred with Ledger API. Please try again later. (HTTP {{status}})' |
|||
NetworkDown: 'Your internet connection seems down. Please try again later.' |
|||
NoAddressesFound: 'No accounts found' |
Loading…
Reference in new issue