Improve error message in the Mendeley importer (#3900)

This commit is contained in:
Tom Najdek 2024-04-08 07:46:59 +02:00 committed by GitHub
parent 66fa9fdc51
commit 91cd9814e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View file

@ -109,9 +109,9 @@ const Zotero_Import_Wizard = { // eslint-disable-line no-unused-vars
.querySelector('#page-done-error > button')
.addEventListener('keydown', this.onReportErrorInteract.bind(this));
document
.getElementById('mendeley-username').addEventListener('keyup', this.onMendeleyAuthKeyUp.bind(this));
.getElementById('mendeley-username').addEventListener('input', this.onMendeleyAuthInput.bind(this));
document
.getElementById('mendeley-password').addEventListener('keyup', this.onMendeleyAuthKeyUp.bind(this));
.getElementById('mendeley-password').addEventListener('input', this.onMendeleyAuthInput.bind(this));
document
.getElementById('relink-only-checkbox').addEventListener('command', this.onRelinkOnlyChange.bind(this));
@ -256,8 +256,23 @@ const Zotero_Import_Wizard = { // eslint-disable-line no-unused-vars
}
catch (e) {
const feedbackEl = document.getElementById('mendeley-online-login-feedback');
feedbackEl.textContent = '';
if (e instanceof Zotero.HTTP.SecurityException) {
feedbackEl.removeAttribute('data-l10n-id');
feedbackEl.removeAttribute('data-l10n-args');
feedbackEl.textContent = e.message;
}
else if (e instanceof Zotero.HTTP.UnexpectedStatusException && (e.status === 400 || e.status === 401 || e.status === 403)) {
feedbackEl.setAttribute('data-l10n-id', 'import-online-wrong-credentials');
feedbackEl.setAttribute('data-l10n-args', JSON.stringify({ targetApp: "Mendeley" }));
this.wizard.canAdvance = false; // change to login/password input will reset this
}
else {
feedbackEl.setAttribute('data-l10n-id', 'import-online-connection-error');
feedbackEl.setAttribute('data-l10n-args', JSON.stringify({ targetApp: "Mendeley" }));
}
feedbackEl.style.display = '';
this.wizard.canAdvance = false; // change to either of the inputs will reset thi
}
finally {
userNameEl.disabled = false;
@ -266,7 +281,7 @@ const Zotero_Import_Wizard = { // eslint-disable-line no-unused-vars
}
},
onMendeleyAuthKeyUp() {
onMendeleyAuthInput() {
document.getElementById('mendeley-online-login-feedback').style.display = 'none';
this.wizard.canAdvance = document.getElementById('mendeley-username').value.length > 0
&& document.getElementById('mendeley-password').value.length > 0;

View file

@ -57,7 +57,7 @@
<html:input type="password" id="mendeley-password" />
</div>
</fieldset>
<div id="mendeley-online-login-feedback" data-l10n-id="import-online-wrong-credentials" data-l10n-args='{"targetApp": "Mendeley"}' />
<div id="mendeley-online-login-feedback" />
</wizardpage>
<wizardpage
pageid="page-options"

View file

@ -184,6 +184,7 @@ import-online-blocked-by-plugin = The import cannot continue with { $plugin } in
import-online-relink-only =
.label = Relink Mendeley Desktop citations
import-online-relink-kb = More Information
import-online-connection-error = { -app-name } could not connect to { $targetApp }. Please check your internet connection and try again.
items-table-cell-notes =
.aria-label = { $count ->

View file

@ -154,9 +154,10 @@
#mendeley-online-login-feedback {
text-align: center;
white-space: pre-wrap;
font-size: 13px;
margin-top: 1.3em;
color: red;
color: var(--accent-orange);
font-weight: 600;
}