Fix deserialization error during login (#145)

Fixes #144 

The error was occurring when querying for server information. The
endpoint used returns information about previous installations and seems
some may be missing a field marked as required in the API. This causes
the deserialization error.

Since the query is just to get the server's name for the UI, we can use
the public server info endpoint instead and also wrap it in a try-catch
since it's not absolutely required.

Additionally, this PR adds exceptions for cases when necessary
information is not available (user id, access token, etc).
This commit is contained in:
damontecres 2025-11-02 17:28:18 -05:00 committed by GitHub
parent fe0f96d413
commit 78322ab0a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -84,13 +84,15 @@ class ServerRepository
} }
Timber.v("Changing user to ${user.name} on ${server.url}") Timber.v("Changing user to ${user.name} on ${server.url}")
apiClient.update(baseUrl = server.url, accessToken = user.accessToken) apiClient.update(baseUrl = server.url, accessToken = user.accessToken)
val userDto = val userDto by apiClient.userApi.getCurrentUser()
apiClient.userApi val updatedServer =
.getCurrentUser() try {
.content val sysInfo by apiClient.systemApi.getPublicSystemInfo()
val sysInfo by apiClient.systemApi.getSystemInfo() server.copy(name = sysInfo.serverName)
} catch (ex: Exception) {
val updatedServer = server.copy(name = sysInfo.serverName) Timber.w(ex, "Exception fetching public system info")
server
}
var updatedUser = var updatedUser =
user.copy( user.copy(
id = userDto.id, id = userDto.id,
@ -171,8 +173,14 @@ class ServerRepository
} }
if (user != null) { if (user != null) {
changeUser(server, user) changeUser(server, user)
} else {
throw IllegalArgumentException("Authentication result's user was null")
} }
} else {
throw IllegalArgumentException("Authentication result's serverId not valid: ${authenticationResult.serverId}")
} }
} else {
throw IllegalArgumentException("Authentication result's access token was null")
} }
} }