Browse Source

Merge pull request #1026 from gre/fix-generic-error-fallback

More robust implementation of Error fallback
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
0e022196f7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/components/TranslatedError.js
  2. 26
      static/i18n/en/errors.yml

15
src/components/TranslatedError.js

@ -22,14 +22,19 @@ class TranslatedError extends PureComponent<Props> {
render() { render() {
const { t, error, field } = this.props const { t, error, field } = this.props
if (!error) return null if (!error) return null
if (typeof error === 'string') return error if (typeof error !== 'object') {
// this case should not happen (it is supposed to be a ?Error)
logger.critical(error)
return null
}
if (error.name) { if (error.name) {
const translation = t(`errors:${error.name}.${field}`, error) const translation = t(`errors:${error.name}.${field}`, error)
// FIXME in case the error don't exist in t we should not return and fallback code after. I just don't know how to check this. FIXME if (translation !== `${error.name}.${field}`) {
return translation // It is translated
return translation
}
} }
logger.warn(`TranslatedError: no translation for '${error.name}'`, error) return t(`errors:generic.${field}`, error)
return error.message || error.name || t(`errors:generic.${field}`)
} }
} }

26
static/i18n/en/errors.yml

@ -1,3 +1,8 @@
# this error is used when we don't want specific wording or as fallback
generic:
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
# the error codes are alphabetically sorted # the error codes are alphabetically sorted
BtcUnmatchedApp: BtcUnmatchedApp:
title: That's the wrong app title: That's the wrong app
@ -20,27 +25,9 @@ DeviceSocketNoHandler:
DisconnectedDevice: DisconnectedDevice:
title: Oops, device was disconnected title: Oops, device was disconnected
description: The connection to the device was lost, so please try again. description: The connection to the device was lost, so please try again.
Error:
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
"Invariant Violation":
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
InternalError:
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
TypeError:
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
ReferenceError:
title: '{{message}}'
description: Something went wrong. Please retry or contact us.
FeeEstimationFailed: FeeEstimationFailed:
title: Sorry, fee estimation failed title: Sorry, fee estimation failed
description: 'Try setting a custom fee (status: {{status}})' description: 'Try setting a custom fee (status: {{status}})'
generic:
title: Sorry, that's an unexpected bug
description: Please retry or contact Ledger Support.
HardResetFail: HardResetFail:
title: Oops, could not reset title: Oops, could not reset
description: Please retry or contact Ledger Support. description: Please retry or contact Ledger Support.
@ -83,9 +70,6 @@ NoAddressesFound:
NotEnoughBalance: NotEnoughBalance:
title: Oops, not enough balance title: Oops, not enough balance
description: Make sure the account to debit has sufficient balance description: Make sure the account to debit has sufficient balance
RangeError:
title: '{{message}}'
description:
TimeoutError: TimeoutError:
title: Oops, a time out occurred title: Oops, a time out occurred
description: It took too long for the server to respond. description: It took too long for the server to respond.

Loading…
Cancel
Save