Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
Handle different decryption errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Jan 8, 2019
1 parent 7f0783c commit 07f4ce1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PageCentered from '../PageCentered';


const propTypes = {
decryptErrorMsg: PropTypes.string.isRequired,
decryptFile: PropTypes.func.isRequired,
decryptStatus: PropTypes.string.isRequired
};
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class PasswordPrompt extends PureComponent {
}

render() {
const { decryptStatus } = this.props;
const { decryptErrorMsg, decryptStatus } = this.props;
const { isSubmitted, password } = this.state;

return (
Expand All @@ -77,7 +78,7 @@ export default class PasswordPrompt extends PureComponent {
<div className="password-prompt-banner">
{
isSubmitted && decryptStatus === 'error'
&& <Banner type="error" message="Incorrect password" />
&& <Banner type="error" message={decryptErrorMsg} />
}
</div>
</PageCentered>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { decryptFile } from '../../../redux/actions/fileActions';

function mapStateToProps(state) {
return {
decryptErrorMsg: state.file.decryptErrorMsg,
decryptStatus: state.file.decryptStatus
};
}
Expand Down
17 changes: 11 additions & 6 deletions src/renderer/redux/actions/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ function setDecryptInProgress() {
};
}

function setDecryptError() {
function setDecryptError(decryptErrorMsg) {
return {
type: 'DECRYPT_ERROR'
type: 'DECRYPT_ERROR',
payload: {
decryptErrorMsg
}
};
}

Expand Down Expand Up @@ -122,11 +125,13 @@ export function decryptFile(password) {
enableMenuItems();
} catch (err) {
// Error reading diary file
if (!err.message.endsWith('bad decrypt')) {
// Other error (not incorrect password error)
console.error(err);
let errorMsg;
if (err.message.endsWith('bad decrypt')) {
errorMsg = 'Incorrect password';
} else {
errorMsg = 'Error while decrypting diary file';
}
dispatch(setDecryptError());
dispatch(setDecryptError(errorMsg));
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/redux/reducers/fileReducer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function file(state = {
decryptErrorMsg: '',
decryptStatus: 'idle', // One of ['idle', 'inProgress', 'error']
encryptStatus: 'idle', // One of ['idle', 'inProgress', 'error']
entries: {},
Expand All @@ -9,18 +10,21 @@ function file(state = {
case 'DECRYPT_IN_PROGRESS': {
return {
...state,
decryptErrorMsg: '',
decryptStatus: 'inProgress'
};
}
case 'DECRYPT_ERROR': {
return {
...state,
decryptErrorMsg: action.payload.decryptErrorMsg,
decryptStatus: 'error'
};
}
case 'DECRYPT_SUCCESS': {
return {
...state,
decryptErrorMsg: '',
decryptStatus: 'idle',
entries: action.payload.entries
};
Expand Down

0 comments on commit 07f4ce1

Please sign in to comment.