fix: try/catch
This commit is contained in:
parent
4183069a9f
commit
ec330b2ac8
|
@ -52,6 +52,9 @@ Accounts::AccountDto Controller::getSelectedAccount()
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: For situations like this, should be better to return a std::optional instead?
|
||||||
|
return Accounts::AccountDto();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::setSelectedAccountKeyUid(QString keyUid)
|
void Controller::setSelectedAccountKeyUid(QString keyUid)
|
||||||
|
|
|
@ -68,7 +68,7 @@ void Module::load()
|
||||||
|
|
||||||
m_view->setModelItems(items);
|
m_view->setModelItems(items);
|
||||||
|
|
||||||
// set the first account as slected one
|
// set the first account as selected one
|
||||||
m_controller->setSelectedAccountKeyUid(items[0].getKeyUid());
|
m_controller->setSelectedAccountKeyUid(items[0].getKeyUid());
|
||||||
Module::setSelectedAccount(items[0]);
|
Module::setSelectedAccount(items[0]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,10 @@ void Service::init()
|
||||||
|
|
||||||
QVector<AccountDto> Service::openedAccounts()
|
QVector<AccountDto> Service::openedAccounts()
|
||||||
{
|
{
|
||||||
// try
|
// TODO: if there's an exception, should we return an empty result? or should we look into using
|
||||||
|
// std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||||
|
try
|
||||||
|
{
|
||||||
auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir));
|
auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir));
|
||||||
QJsonArray multiAccounts = response.m_result;
|
QJsonArray multiAccounts = response.m_result;
|
||||||
QVector<AccountDto> result;
|
QVector<AccountDto> result;
|
||||||
|
@ -49,8 +52,12 @@ QVector<AccountDto> Service::openedAccounts()
|
||||||
result << toAccountDto(value);
|
result << toAccountDto(value);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
//} catch(const std::exception& e){
|
}
|
||||||
// error "error: ", methodName="openedAccounts", errName = e.name, errDesription = e.msg
|
catch(Backend::RpcException& e)
|
||||||
|
{
|
||||||
|
qWarning() << "error: methodName=openedAccounts, errDescription=" << e.what();
|
||||||
|
return QVector<AccountDto>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<GeneratedAccountDto> Service::generatedAccounts()
|
QVector<GeneratedAccountDto> Service::generatedAccounts()
|
||||||
|
@ -66,30 +73,29 @@ QVector<GeneratedAccountDto> Service::generatedAccounts()
|
||||||
|
|
||||||
bool Service::setupAccount(QString accountId, QString password)
|
bool Service::setupAccount(QString accountId, QString password)
|
||||||
{
|
{
|
||||||
//try:
|
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||||
|
try
|
||||||
|
{
|
||||||
QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces));
|
QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces));
|
||||||
QJsonObject accountData(Service::getAccountDataForAccountId(accountId));
|
QJsonObject accountData(Service::getAccountDataForAccountId(accountId));
|
||||||
QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId));
|
QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId));
|
||||||
QJsonObject settings(Service::getAccountSettings(accountId, installationId));
|
QJsonObject settings(Service::getAccountSettings(accountId, installationId));
|
||||||
QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId));
|
QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId));
|
||||||
|
|
||||||
// if(accountDataJson.isNil or subaccountDataJson.isNil or settingsJson.isNil or
|
|
||||||
// nodeConfigJson.isNil):
|
|
||||||
//let description = "at least one json object is not prepared well"
|
|
||||||
//error "error: ", methodName="setupAccount", errDesription = description
|
|
||||||
//return false
|
|
||||||
|
|
||||||
QString hashedPassword(Backend::Utils::hashString(password));
|
QString hashedPassword(Backend::Utils::hashString(password));
|
||||||
|
|
||||||
Service::storeDerivedAccounts(accountId, hashedPassword, PATHS);
|
Service::storeDerivedAccounts(accountId, hashedPassword, PATHS);
|
||||||
|
|
||||||
m_loggedInAccount = Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig);
|
m_loggedInAccount =
|
||||||
|
Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig);
|
||||||
|
|
||||||
return Service::getLoggedInAccount().isValid();
|
return Service::getLoggedInAccount().isValid();
|
||||||
|
}
|
||||||
//except Exception as e:
|
catch(exception& e)
|
||||||
// error "error: ", methodName="setupAccount", errName = e.name, errDesription = e.msg
|
{
|
||||||
//return false*/
|
qWarning() << "error: methodName=setupAccount, errDescription=" << e.what();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountDto Service::getLoggedInAccount()
|
AccountDto Service::getLoggedInAccount()
|
||||||
|
@ -121,7 +127,9 @@ bool Service::importMnemonic(QString mnemonic)
|
||||||
|
|
||||||
QString Service::login(AccountDto account, QString password)
|
QString Service::login(AccountDto account, QString password)
|
||||||
{
|
{
|
||||||
//try:
|
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||||
|
try
|
||||||
|
{
|
||||||
QString hashedPassword(Backend::Utils::hashString(password));
|
QString hashedPassword(Backend::Utils::hashString(password));
|
||||||
|
|
||||||
QString thumbnailImage;
|
QString thumbnailImage;
|
||||||
|
@ -148,10 +156,12 @@ QString Service::login(AccountDto account, QString password)
|
||||||
m_loggedInAccount = account;
|
m_loggedInAccount = account;
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
//except Exception as e:
|
catch(exception& e)
|
||||||
//error "error: ", methodName="setupAccount", errName = e.name, errDesription = e.msg
|
{
|
||||||
//return e.msg
|
qWarning() << "error: methodName=login, errDescription=" << e.what();
|
||||||
|
return e.what();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::clear()
|
void Service::clear()
|
||||||
|
@ -195,14 +205,19 @@ DerivedAccounts Service::storeDerivedAccounts(QString accountId, QString hashedP
|
||||||
Accounts::AccountDto Service::saveAccountAndLogin(
|
Accounts::AccountDto Service::saveAccountAndLogin(
|
||||||
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config)
|
QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config)
|
||||||
{
|
{
|
||||||
//try:
|
// TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html
|
||||||
|
try
|
||||||
|
{
|
||||||
auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config);
|
auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config);
|
||||||
|
|
||||||
m_isFirstTimeAccountLogin = true;
|
m_isFirstTimeAccountLogin = true;
|
||||||
return toAccountDto(account);
|
return toAccountDto(account);
|
||||||
|
}
|
||||||
// except Exception as e:
|
catch(exception& e)
|
||||||
// error "error: ", methodName="saveAccountAndLogin", errName = e.name, errDesription = e.msg
|
{
|
||||||
|
qWarning() << "error: methodName=saveAccountAndLogin, errDescription=" << e.what();
|
||||||
|
return Accounts::AccountDto();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject Service::prepareAccountJsonObject(const GeneratedAccountDto account)
|
QJsonObject Service::prepareAccountJsonObject(const GeneratedAccountDto account)
|
||||||
|
@ -233,6 +248,9 @@ QJsonObject Service::getAccountDataForAccountId(QString accountId)
|
||||||
return Service::prepareAccountJsonObject(m_importedAccount);
|
return Service::prepareAccountJsonObject(m_importedAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Should we use instead a std::optional?
|
||||||
|
throw std::runtime_error("account not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray Service::prepareSubaccountJsonObject(GeneratedAccountDto account)
|
QJsonArray Service::prepareSubaccountJsonObject(GeneratedAccountDto account)
|
||||||
|
@ -255,7 +273,6 @@ QJsonArray Service::getSubaccountDataForAccountId(QString accountId)
|
||||||
{
|
{
|
||||||
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
foreach(const GeneratedAccountDto& acc, m_generatedAccounts)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(acc.id == accountId)
|
if(acc.id == accountId)
|
||||||
{
|
{
|
||||||
return prepareSubaccountJsonObject(acc);
|
return prepareSubaccountJsonObject(acc);
|
||||||
|
@ -268,6 +285,9 @@ QJsonArray Service::getSubaccountDataForAccountId(QString accountId)
|
||||||
return prepareSubaccountJsonObject(m_importedAccount);
|
return prepareSubaccountJsonObject(m_importedAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Should we use instead a std::optional?
|
||||||
|
throw std::runtime_error("account not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString generateSigningPhrase(int count)
|
QString generateSigningPhrase(int count)
|
||||||
|
@ -326,6 +346,9 @@ QJsonObject Service::getAccountSettings(QString accountId, QString installationI
|
||||||
return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId);
|
return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Should we use instead a std::optional?
|
||||||
|
throw std::runtime_error("account not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray getNodes(const QJsonObject fleet, QString nodeType)
|
QJsonArray getNodes(const QJsonObject fleet, QString nodeType)
|
||||||
|
|
Loading…
Reference in New Issue