improving error handling
This commit is contained in:
parent
100d955e1a
commit
35045bb69a
122
js/privatebin.js
122
js/privatebin.js
@ -3990,12 +3990,12 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
Alert.hideLoading();
|
Alert.hideLoading();
|
||||||
TopNav.showViewButtons();
|
TopNav.showViewButtons();
|
||||||
|
|
||||||
// show error message
|
// …show error message…
|
||||||
Alert.showError(
|
Alert.showError(
|
||||||
Uploader.parseUploadError(status, data, 'post comment')
|
Uploader.parseUploadError(status, data, 'post comment')
|
||||||
);
|
);
|
||||||
|
|
||||||
// reset error handler
|
// …and reset error handler
|
||||||
Alert.setCustomHandler(null);
|
Alert.setCustomHandler(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -4009,22 +4009,19 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
Uploader.setUnencryptedData('parentid', parentid);
|
Uploader.setUnencryptedData('parentid', parentid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// encrypt data
|
// start promises to encrypt data…
|
||||||
try {
|
let dataPromises = [];
|
||||||
// start promisesat the same time and wait thereafter
|
dataPromises.push(Uploader.setData('data', plainText));
|
||||||
let settingData = [];
|
if (nickname.length > 0) {
|
||||||
settingData.push(Uploader.setData('data', plainText));
|
dataPromises.push(Uploader.setData('nickname', nickname));
|
||||||
|
|
||||||
if (nickname.length > 0) {
|
|
||||||
settingData(Uploader.setData('nickname', nickname));
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.all(settingData);
|
|
||||||
} catch (e) {
|
|
||||||
Alert.showError(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Uploader.run();
|
// …and upload when they are all done
|
||||||
|
Promise.all(dataPromises).then(() => {
|
||||||
|
Uploader.run();
|
||||||
|
}).catch((e) => {
|
||||||
|
Alert.showError(e);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4194,7 +4191,7 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
PasteViewer.run();
|
PasteViewer.run();
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
throw 'failed to decipher paste text: ' + err;
|
displayDecryptionError('failed to decipher paste text: ' + err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4214,10 +4211,10 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
let attachmentPromise = decryptOrPromptPassword(key, password, paste.attachment);
|
let attachmentPromise = decryptOrPromptPassword(key, password, paste.attachment);
|
||||||
let attachmentNamePromise = decryptOrPromptPassword(key, password, paste.attachmentname);
|
let attachmentNamePromise = decryptOrPromptPassword(key, password, paste.attachmentname);
|
||||||
attachmentPromise.catch((err) => {
|
attachmentPromise.catch((err) => {
|
||||||
throw 'failed to decipher attachment: ' + err;
|
displayDecryptionError('failed to decipher attachment: ' + err);
|
||||||
})
|
})
|
||||||
attachmentNamePromise.catch((err) => {
|
attachmentNamePromise.catch((err) => {
|
||||||
throw 'failed to decipher attachment name: ' + err;
|
displayDecryptionError('failed to decipher attachment name: ' + err);
|
||||||
})
|
})
|
||||||
Promise.all([attachmentPromise, attachmentNamePromise]).then((results) => {
|
Promise.all([attachmentPromise, attachmentNamePromise]).then((results) => {
|
||||||
if (!results.some((result) => {
|
if (!results.some((result) => {
|
||||||
@ -4247,12 +4244,15 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
let commentDecryptionPromises = [];
|
let commentDecryptionPromises = [];
|
||||||
// iterate over comments
|
// iterate over comments
|
||||||
for (var i = 0; i < paste.comments.length; ++i) {
|
for (var i = 0; i < paste.comments.length; ++i) {
|
||||||
commentDecryptionPromises.append(
|
commentDecryptionPromises.push(
|
||||||
CryptTool.decipher(key, password, paste.comments[i].data)
|
CryptTool.decipher(key, password, paste.comments[i].data)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Promise.all(commentDecryptionPromises).then((plaintexts) => {
|
Promise.all(commentDecryptionPromises).then((plaintexts) => {
|
||||||
for (var i = 0; i < paste.comments.length; ++i) {
|
for (var i = 0; i < paste.comments.length; ++i) {
|
||||||
|
if (plaintexts[i] === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var comment = paste.comments[i];
|
var comment = paste.comments[i];
|
||||||
DiscussionViewer.addComment(
|
DiscussionViewer.addComment(
|
||||||
comment,
|
comment,
|
||||||
@ -4264,6 +4264,27 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* displays and logs decryption errors
|
||||||
|
*
|
||||||
|
* @name PasteDecrypter.displayDecryptionError
|
||||||
|
* @private
|
||||||
|
* @function
|
||||||
|
* @param {string} message
|
||||||
|
*/
|
||||||
|
function displayDecryptionError(message)
|
||||||
|
{
|
||||||
|
Alert.hideLoading();
|
||||||
|
|
||||||
|
// log detailed error, but display generic translation
|
||||||
|
console.error(message);
|
||||||
|
Alert.showError('Could not decrypt data. Did you enter a wrong password? Retry with the button at the top.');
|
||||||
|
|
||||||
|
// reset password, so it can be re-entered
|
||||||
|
Prompt.reset();
|
||||||
|
TopNav.showRetryButton();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show decrypted text in the display area, including discussion (if open)
|
* show decrypted text in the display area, including discussion (if open)
|
||||||
*
|
*
|
||||||
@ -4282,50 +4303,43 @@ jQuery.PrivateBin = (function($, sjcl, RawDeflate) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = Model.getPasteKey(),
|
let key = Model.getPasteKey(),
|
||||||
password = Prompt.getPassword();
|
password = Prompt.getPassword(),
|
||||||
|
decrytionPromises = [];
|
||||||
|
|
||||||
// try to decrypt the paste
|
TopNav.setRetryCallback(function () {
|
||||||
try {
|
TopNav.hideRetryButton();
|
||||||
// decrypt attachments
|
me.run(paste);
|
||||||
if (paste.attachment && AttachmentViewer.hasAttachmentData()) {
|
});
|
||||||
// try to decrypt paste and if it fails (because the password is
|
|
||||||
// missing) return to let JS continue and wait for user
|
// decrypt attachments
|
||||||
|
if (paste.attachment && AttachmentViewer.hasAttachmentData()) {
|
||||||
|
// try to decrypt paste and if it fails (because the password is
|
||||||
|
// missing) return to let JS continue and wait for user
|
||||||
|
decrytionPromises.push(
|
||||||
decryptAttachment(paste, key, password).then((attachementIsDecrypted) => {
|
decryptAttachment(paste, key, password).then((attachementIsDecrypted) => {
|
||||||
if (attachementIsDecrypted) {
|
if (attachementIsDecrypted) {
|
||||||
// ignore empty paste, as this is allowed when pasting attachments
|
// ignore empty paste, as this is allowed when pasting attachments
|
||||||
decryptPaste(paste, key, password, true);
|
return decryptPaste(paste, key, password, true);
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
} else {
|
);
|
||||||
decryptPaste(paste, key, password)
|
} else {
|
||||||
}
|
decrytionPromises.push(decryptPaste(paste, key, password))
|
||||||
|
}
|
||||||
|
|
||||||
// shows the remaining time (until) deletion
|
// shows the remaining time (until) deletion
|
||||||
PasteStatus.showRemainingTime(paste.meta);
|
PasteStatus.showRemainingTime(paste.meta);
|
||||||
|
|
||||||
// if the discussion is opened on this paste, display it
|
// if the discussion is opened on this paste, display it
|
||||||
if (paste.meta.opendiscussion) {
|
if (paste.meta.opendiscussion) {
|
||||||
decryptComments(paste, key, password);
|
decrytionPromises(decryptComments(paste, key, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Promise.all(decrytionPromises).then(() => {
|
||||||
Alert.hideLoading();
|
Alert.hideLoading();
|
||||||
TopNav.showViewButtons();
|
TopNav.showViewButtons();
|
||||||
} catch(err) {
|
});
|
||||||
Alert.hideLoading();
|
|
||||||
|
|
||||||
// log and show error
|
|
||||||
console.error(err);
|
|
||||||
Alert.showError('Could not decrypt data. Did you enter a wrong password? Retry with the button at the top.');
|
|
||||||
// reset password, so it can be re-entered and sow retry button
|
|
||||||
Prompt.reset();
|
|
||||||
TopNav.setRetryCallback(function () {
|
|
||||||
TopNav.hideRetryButton();
|
|
||||||
|
|
||||||
me.run(paste);
|
|
||||||
});
|
|
||||||
TopNav.showRetryButton();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +71,7 @@ if ($MARKDOWN):
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LONouflL+fHKsWtBahP1b1P0ZubtRPpNl8bh0VFrlbbux7N3JOgK28iWU7tVcB5daxHhgOHAFqagn2369a7gFg==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-QoyJMD+9as5QQUHm4/mdiFvqHA5VvFqo+N5pn1xNFA6t5bpxS8dI1HwkFbgTQjp/cJrGqTXQ6tDDAiUixiGXNQ==" crossorigin="anonymous"></script>
|
||||||
<!--[if lt IE 10]>
|
<!--[if lt IE 10]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
@ -49,7 +49,7 @@ if ($MARKDOWN):
|
|||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.7.js" integrity="sha512-VnKJHLosO8z2ojNvWk9BEKYqnhZyWK9rM90FgZUUEp/PRnUqR5OLLKE0a3BkVmn7YgB7LXRrjHgFHQYKd6DAIA==" crossorigin="anonymous"></script>
|
||||||
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LONouflL+fHKsWtBahP1b1P0ZubtRPpNl8bh0VFrlbbux7N3JOgK28iWU7tVcB5daxHhgOHAFqagn2369a7gFg==" crossorigin="anonymous"></script>
|
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-QoyJMD+9as5QQUHm4/mdiFvqHA5VvFqo+N5pn1xNFA6t5bpxS8dI1HwkFbgTQjp/cJrGqTXQ6tDDAiUixiGXNQ==" crossorigin="anonymous"></script>
|
||||||
<!--[if lt IE 10]>
|
<!--[if lt IE 10]>
|
||||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
Loading…
Reference in New Issue
Block a user