Skip to content

Commit

Permalink
Ensure only Errors are thrown/rejected
Browse files Browse the repository at this point in the history
Whenever using the `throw` keyword or calling `reject` in a Promise,
the value passed should be an Error. Various tools expect thrown
"errors" to be errors; this is the convention. Using Error types is
also more useful for debugging, as they have stack traces.
  • Loading branch information
Gudahtt committed Mar 6, 2020
1 parent 1353086 commit f9072c1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ export class BrowserTab extends PureComponent {
this.setState({ showApprovalDialog: false, showApprovalDialogHostname: undefined });
this.approvalRequest &&
this.approvalRequest.reject &&
this.approvalRequest.reject('User rejected account access');
this.approvalRequest.reject(new Error('User rejected account access'));
};

renderApprovalModal = () => {
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/ImportWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ImportWallet extends PureComponent {
} catch (e) {
if (!firstAttempt) {
this.props.navigation.goBack();
if (e.toString() === 'sync-timeout') {
if (e.message === 'Sync::timeout') {
Alert.alert(
strings('sync_with_extension.outdated_qr_code'),
strings('sync_with_extension.outdated_qr_code_desc')
Expand Down
2 changes: 1 addition & 1 deletion app/components/Views/SyncWithExtension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SyncWithExtension extends PureComponent {
} catch (e) {
if (!firstAttempt) {
this.props.navigation.goBack();
if (e.toString() === 'sync-timeout') {
if (e.message === 'Sync::timeout') {
Alert.alert(
strings('sync_with_extension.outdated_qr_code'),
strings('sync_with_extension.outdated_qr_code_desc')
Expand Down
2 changes: 1 addition & 1 deletion app/core/WalletConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class WalletConnect {
});
hub.on('walletconnectSessionRequest::rejected', peerId => {
if (peerInfo.peerId === peerId) {
reject(false);
reject(new Error('walletconnectSessionRequest::rejected'));
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/util/blockies.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@

function buildOpts(opts) {
if (!opts.seed) {
throw 'No seed provided';
throw new Error('No seed provided');
}

seedrand(opts.seed);
Expand Down
5 changes: 3 additions & 2 deletions app/util/syncWithExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export default class PubNubWrapper {
() => {
setTimeout(() => {
if (this.timeout) {
Logger.error('Sync::timeout');
reject('sync-timeout');
const error = new Error('Sync::timeout');
Logger.error(error);
reject(error);
} else {
resolve();
}
Expand Down

0 comments on commit f9072c1

Please sign in to comment.