[editor] Stopped user preferences throwing an exception

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2025-07-05 10:47:49 +02:00
committed by Yannik Bloscheck
parent 7bfb488f1d
commit 9951ebece7
2 changed files with 24 additions and 17 deletions

View File

@@ -151,25 +151,33 @@ bool ServerApi06::TestOSMUser(std::string const & userName)
UserPreferences ServerApi06::GetUserPreferences() const UserPreferences ServerApi06::GetUserPreferences() const
{ {
OsmOAuth::Response const response = m_auth.Request("/user/details"); try {
if (response.first != OsmOAuth::HTTP::OK) OsmOAuth::Response const response = m_auth.Request("/user/details");
MYTHROW(CantGetUserPreferences, (response)); if (response.first != OsmOAuth::HTTP::OK)
MYTHROW(CantGetUserPreferences, (response));
pugi::xml_document details; pugi::xml_document details;
if (!details.load_string(response.second.c_str())) if (!details.load_string(response.second.c_str()))
MYTHROW(CantParseUserPreferences, (response)); MYTHROW(CantParseUserPreferences, (response));
pugi::xml_node const user = details.child("osm").child("user"); pugi::xml_node const user = details.child("osm").child("user");
if (!user || !user.attribute("id")) if (!user || !user.attribute("id"))
MYTHROW(CantParseUserPreferences, ("No <user> or 'id' attribute", response)); MYTHROW(CantParseUserPreferences, ("No <user> or 'id' attribute", response));
UserPreferences pref; UserPreferences pref;
pref.m_id = user.attribute("id").as_ullong(); pref.m_id = user.attribute("id").as_ullong();
pref.m_displayName = user.attribute("display_name").as_string(); pref.m_displayName = user.attribute("display_name").as_string();
pref.m_accountCreated = base::StringToTimestamp(user.attribute("account_created").as_string()); pref.m_accountCreated = base::StringToTimestamp(user.attribute("account_created").as_string());
pref.m_imageUrl = user.child("img").attribute("href").as_string(); pref.m_imageUrl = user.child("img").attribute("href").as_string();
pref.m_changesets = user.child("changesets").attribute("count").as_uint(); pref.m_changesets = user.child("changesets").attribute("count").as_uint();
return pref; return pref;
}
catch (std::exception const & e)
{
LOG(LWARNING, ("Can't load user preferences from server: ", e.what()));
}
return {};
} }
OsmOAuth::Response ServerApi06::GetXmlFeaturesInRect(double minLat, double minLon, double maxLat, double maxLon) const OsmOAuth::Response ServerApi06::GetXmlFeaturesInRect(double minLat, double minLon, double maxLat, double maxLon) const

View File

@@ -50,7 +50,6 @@ public:
/// @returns true if user have registered/signed up even if his email address was not confirmed yet. /// @returns true if user have registered/signed up even if his email address was not confirmed yet.
bool TestOSMUser(std::string const & userName); bool TestOSMUser(std::string const & userName);
/// Get OSM user preferences in a convenient struct. /// Get OSM user preferences in a convenient struct.
/// Throws in case of any error.
UserPreferences GetUserPreferences() const; UserPreferences GetUserPreferences() const;
/// Please use at least created_by=* and comment=* tags. /// Please use at least created_by=* and comment=* tags.
/// @returns created changeset ID. /// @returns created changeset ID.