From 48c0b2afcebdb68d4b556f953fad2916757fe412 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Wed, 20 Feb 2019 16:35:28 +0100 Subject: [PATCH 1/2] add more user-friendly error messages --- src/components/modals/QrModal/index.js | 64 ++++++++++++++++---------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/components/modals/QrModal/index.js b/src/components/modals/QrModal/index.js index 1eef2b10..25fb353f 100644 --- a/src/components/modals/QrModal/index.js +++ b/src/components/modals/QrModal/index.js @@ -38,11 +38,18 @@ const CameraPlaceholder = styled(P)` padding: 10px 0; `; -const Error = styled(P)` - text-align: center; +const Error = styled.div` padding: 10px 0; +`; + +const ErrorTitle = styled(P)` + text-align: center; color: ${colors.ERROR_PRIMARY}; `; +const ErrorMessage = styled.span` + text-align: center; + color: ${colors.TEXT_PRIMARY}; +`; const StyledQrReader = styled(QrReader)` padding: 10px 0; @@ -95,14 +102,25 @@ class QrModal extends React.Component { } handleError = (err: any) => { - console.log(err); - this.setState({ - error: err, - }); - + // log thrown error + console.error(err); if (this.props.onError) { this.props.onError(err); } + + if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError') { + this.setState({ + error: 'Permission to access the camera was denied.', + }); + } else if (err.name === 'NotFoundError' || err.name === 'DevicesNotFoundError') { + this.setState({ + error: 'The camera was not recognized.', + }); + } else { + this.setState({ + error: 'Unknown error. See console logs for details.', + }); + } } handleCancel = () => { @@ -123,29 +141,25 @@ class QrModal extends React.Component { /> -

Scan an address from a QR code

- {!this.state.readerLoaded && ( - - Waiting for camera... - - ) - } -
- - +

Scan QR code

+ {!this.state.readerLoaded && !this.state.error && Waiting for camera...} {this.state.error && ( - {this.state.error.toString()} + Oops! Something went wrong! + {this.state.error.toString()} )}
+ {!this.state.error && ( + + )} ); } From c7f4796191532c71f35d31bec826be4edd7072ad Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Wed, 20 Feb 2019 16:49:49 +0100 Subject: [PATCH 2/2] handle NotReadableError --- src/components/modals/QrModal/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/modals/QrModal/index.js b/src/components/modals/QrModal/index.js index 25fb353f..2666584a 100644 --- a/src/components/modals/QrModal/index.js +++ b/src/components/modals/QrModal/index.js @@ -108,7 +108,8 @@ class QrModal extends React.Component { this.props.onError(err); } - if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError') { + if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError' + || err.name === 'NotReadableError' || err.name === 'TrackStartError') { this.setState({ error: 'Permission to access the camera was denied.', });