Skip to content

Commit 96cb46f

Browse files
committed
ConnectionValidator: Surface 401 instead of Exception
For #172
1 parent 7cc267c commit 96cb46f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

opencloudComLibrary/src/main/java/eu/opencloud/android/lib/common/ConnectionValidator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,11 @@ class ConnectionValidator(
177177
*/
178178
private fun checkUnauthorizedAccess(client: OpenCloudClient, singleSessionManager: SingleSessionManager, status: Int): Boolean {
179179
var credentialsWereRefreshed = false
180-
val account = client.account
181-
val credentials = account.credentials
180+
// During initial OAuth login the client has bearer credentials but no Android Account yet
181+
// (the Account is persisted only after this call succeeds). Skip refresh — there's nothing
182+
// to refresh against — otherwise we'd NPE on account.credentials / savedAccount below.
183+
val account: OpenCloudAccount = client.account ?: return false
184+
val credentials: OpenCloudCredentials = account.credentials ?: return false
182185
if (shouldInvalidateAccountCredentials(credentials, account, status)) {
183186
invalidateAccountCredentials(account, credentials)
184187

0 commit comments

Comments
 (0)