From 78322ab0a503f51de055ad6546eec60091d3db2b Mon Sep 17 00:00:00 2001 From: damontecres <154766448+damontecres@users.noreply.github.com> Date: Sun, 2 Nov 2025 17:28:18 -0500 Subject: [PATCH] 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). --- .../wholphin/data/ServerRepository.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt index 8975579f..9b910c78 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/ServerRepository.kt @@ -84,13 +84,15 @@ class ServerRepository } Timber.v("Changing user to ${user.name} on ${server.url}") apiClient.update(baseUrl = server.url, accessToken = user.accessToken) - val userDto = - apiClient.userApi - .getCurrentUser() - .content - val sysInfo by apiClient.systemApi.getSystemInfo() - - val updatedServer = server.copy(name = sysInfo.serverName) + val userDto by apiClient.userApi.getCurrentUser() + val updatedServer = + try { + val sysInfo by apiClient.systemApi.getPublicSystemInfo() + server.copy(name = sysInfo.serverName) + } catch (ex: Exception) { + Timber.w(ex, "Exception fetching public system info") + server + } var updatedUser = user.copy( id = userDto.id, @@ -171,8 +173,14 @@ class ServerRepository } if (user != null) { 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") } }