Skip to content

Commit 8dd8456

Browse files
committed
fix: catch error in get_api and return a helper::unexpected
also add break to the switch, where I forgot them
1 parent eea3d82 commit 8dd8456

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/lobby/api.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ lobby::API::API(const std::string& api_url)
6363
throw std::runtime_error("Couldn't setup authentication");
6464
}
6565
} else {
66-
spdlog::error("API {}", value.error());
66+
spdlog::info("API: Key not found, so probably not logged in already: {}", value.error());
6767
}
6868
}
6969

@@ -83,17 +83,22 @@ lobby::API::~API() = default;
8383

8484
helper::expected<lobby::API, std::string> lobby::API::get_api(const std::string& url) {
8585

86-
API api{ url };
86+
try {
8787

88-
const auto reachable = api.check_reachability();
88+
API api{ url };
8989

90-
if (not reachable.has_value()) {
91-
return helper::unexpected<std::string>{ reachable.error() };
92-
}
90+
const auto reachable = api.check_reachability();
91+
92+
if (not reachable.has_value()) {
93+
return helper::unexpected<std::string>{ reachable.error() };
94+
}
9395

94-
//TODO(Totto): once version is standard, check here if the version is supported
96+
//TODO(Totto): once version is standard, check here if the version is supported
9597

96-
return api;
98+
return api;
99+
} catch (const std::exception& err) {
100+
return helper::unexpected<std::string>{ err.what() };
101+
}
97102
}
98103

99104
void lobby::API::check_url(const std::string& url, std::function<void(const bool success)>&& callback) {

src/lobby/credentials/secret.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ secret::SecretStorage::SecretStorage(KeyringType type) : m_type{ type } {
3535
switch (m_type) {
3636
case secret::KeyringType::User:
3737
key_type = KEY_SPEC_USER_KEYRING;
38+
break;
3839
case secret::KeyringType::Session:
3940
key_type = KEY_SPEC_SESSION_KEYRING;
41+
break;
4042
case secret::KeyringType::Persistent: {
4143
// -1 stands for current uid, 0 stands for: do not create a link to another keyring
4244
this->m_ring_id = keyctl_get_persistent(-1, 0);

0 commit comments

Comments
 (0)