still refactoring some promise stuff

This commit is contained in:
quenousimporte 2023-09-21 21:55:59 +02:00
parent fc3ffcc681
commit d63621387e
1 changed files with 26 additions and 28 deletions

54
main.js
View File

@ -423,7 +423,7 @@ function decryptstring(str)
{ {
if (!str.startsWith("-----BEGIN PGP MESSAGE-----")) if (!str.startsWith("-----BEGIN PGP MESSAGE-----"))
{ {
console.log("string is not encrypted"); // console.log(str + ": string is not encrypted");
return Promise.resolve(str); return Promise.resolve(str);
} }
console.log("decrypting..."); console.log("decrypting...");
@ -1540,41 +1540,39 @@ function queryremote(params)
else else
{ {
var data = {}; var data = {};
try
{
decryptstring(xhr.responseText)
.then(decrypted =>
{
data = JSON.parse(decrypted);
if (data.error) decryptstring(xhr.responseText)
.then(decrypted =>
{
data = JSON.parse(decrypted);
if (data.error)
{
if (data.error == "authent")
{ {
if (data.error == "authent") failed();
{ togglepassword();
failed();
togglepassword();
}
else
{
failed("Remote handler returned an error: " + data.error);
}
}
else if (data.warning)
{
console.warn("Remote warning: " + data.warning);
} }
else else
{ {
authentpage.hidden = true; failed("Remote handler returned an error: " + data.error);
notepage.style.display = "table";
apply(data);
} }
}); }
} else if (data.warning)
catch(error) {
console.warn("Remote warning: " + data.warning);
}
else
{
authentpage.hidden = true;
notepage.style.display = "table";
apply(data);
}
})
.catch( error =>
{ {
failed("Handler result is not valid. JS error: " + error); failed("Handler result is not valid. JS error: " + error);
} });
} }
} }