Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ApplicationPasswordLoginViewModel @Inject constructor(
fun setupSite(rawData: String) {
viewModelScope.launch {
if (rawData.isEmpty()) {
appLogWrapper.e(AppLog.T.MAIN, "Cannot store credentials: rawData is empty")
appLogWrapper.e(AppLog.T.MAIN, "A_P: Cannot store credentials: rawData is empty")
_onFinishedEvent.emit(
NavigationActionData(
showSiteSelector = false,
Expand Down Expand Up @@ -95,7 +95,10 @@ class ApplicationPasswordLoginViewModel @Inject constructor(
try {
applicationPasswordLoginHelper.storeApplicationPasswordCredentialsFrom(urlLogin)
} catch (e: Exception) {
appLogWrapper.e(AppLog.T.DB, "Error storing credentials: ${e.stackTraceToString()}")
appLogWrapper.e(
AppLog.T.DB,
"A_P: Error storing credentials: ${e.stackTraceToString()}"
)
false
}
}
Expand All @@ -109,9 +112,14 @@ class ApplicationPasswordLoginViewModel @Inject constructor(
) = withContext(ioDispatcher) {
try {
if (username.isEmpty() || password.isEmpty() || siteUrl.isEmpty() || apiRootUrl.isEmpty()) {
appLogWrapper.e(AppLog.T.MAIN, "Cannot fetch sites for credential storing: " +
"Username: $username, Password: ${password.isEmpty()}, SiteUrl: $siteUrl, " +
"API Root URL: $apiRootUrl")
appLogWrapper.e(
AppLog.T.MAIN,
"A_P: Cannot fetch sites for credential storing" +
" - username isEmpty=${username.isEmpty()}" +
", password isEmpty=${password.isEmpty()}" +
", siteUrl isEmpty=${siteUrl.isEmpty()}" +
", apiRootUrl isEmpty=${apiRootUrl.isEmpty()}"
)
emitErrorFetching(siteUrl)
} else {
val xmlRpcEndpoint =
Expand All @@ -128,7 +136,10 @@ class ApplicationPasswordLoginViewModel @Inject constructor(
)
}
} catch (e: Exception) {
appLogWrapper.e(AppLog.T.API, "Error fetching sites: ${e.stackTraceToString()}")
appLogWrapper.e(
AppLog.T.API,
"A_P: Error fetching sites: ${e.stackTraceToString()}"
)
emitErrorFetching(siteUrl)
}
}
Expand All @@ -150,7 +161,19 @@ class ApplicationPasswordLoginViewModel @Inject constructor(
val currentNormalizedUrl = UrlUtils.normalizeUrl(currentUrlLogin?.siteUrl)
val site = siteStore.sites.firstOrNull { UrlUtils.normalizeUrl(it.url) == currentNormalizedUrl }
if (event.rowsAffected < 1 || site == null || applicationPasswordLoginHelper.siteHasBadCredentials(site)) {
appLogWrapper.e(AppLog.T.MAIN, "Site not found or credentials are empty.")
appLogWrapper.e(
AppLog.T.MAIN,
"A_P: onSiteChanged failed" +
" for: ${currentUrlLogin?.siteUrl}" +
" - rowsAffected=${event.rowsAffected}" +
", siteFound=${site != null}" +
", badCredentials=${
site?.let {
applicationPasswordLoginHelper
.siteHasBadCredentials(it)
}
}"
)
_onFinishedEvent.emit(
NavigationActionData(
showSiteSelector = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ class ApplicationPasswordLoginHelper @Inject constructor(
) {
appLogWrapper.e(
AppLog.T.DB,
"A_P: Cannot save application password credentials for: ${urlLogin.siteUrl} - bad data"
"A_P: Cannot save application password credentials" +
" for: ${urlLogin.siteUrl}" +
" - apiRootUrl isNull=${urlLogin.apiRootUrl == null}" +
", user isEmpty=${urlLogin.user.isNullOrEmpty()}" +
", password isEmpty=${urlLogin.password.isNullOrEmpty()}" +
", siteUrl isNull=${urlLogin.siteUrl == null}" +
", alreadyProcessed=" +
"${urlLogin.siteUrl == processedAppPasswordData}"
)
return false
}
Expand All @@ -116,7 +123,11 @@ class ApplicationPasswordLoginHelper @Inject constructor(
} else {
appLogWrapper.e(
AppLog.T.DB,
"A_P: Cannot save application password credentials for: ${urlLogin.siteUrl} - null site"
"A_P: Cannot save application password" +
" credentials for: ${urlLogin.siteUrl}" +
" (normalized: $normalizedUrl)" +
" - site not found in store" +
" (${siteStore.sites.size} sites available)"
)
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,26 @@ class ApplicationPasswordAutoAuthDialogViewModel @Inject constructor(
}

else -> {
appLogWrapper.e(AppLog.T.API, "Error creating application password")
logCreationError(site.url, "response type: ${response::class.simpleName}")
fallbackToManualLogin(site.url)
}
}
} catch (e: Exception) {
appLogWrapper.e(AppLog.T.API, "Exception creating application password: ${e.message}")
logCreationError(site.url, e.message.orEmpty())
fallbackToManualLogin(site.url)
} finally {
_isLoading.value = false
}
}
}

private fun logCreationError(siteUrl: String, detail: String) {
appLogWrapper.e(
AppLog.T.API,
"A_P: Error creating application password for: $siteUrl - $detail"
)
}

@Suppress("TooGenericExceptionCaught")
private fun enableApplicationPasswordIfNecessary() {
if (!experimentalFeatures.isEnabled(Feature.EXPERIMENTAL_APPLICATION_PASSWORD_FEATURE)) {
Expand All @@ -115,7 +122,11 @@ class ApplicationPasswordAutoAuthDialogViewModel @Inject constructor(
val authUrl = applicationPasswordLoginHelper.getAuthorizationUrlComplete(siteUrl)
_navigationEvent.emit(NavigationEvent.FallbackToManualLogin(authUrl))
} catch (e: Exception) {
appLogWrapper.e(AppLog.T.API, "Failed to get authorization URL: ${e.message}")
appLogWrapper.e(
AppLog.T.API,
"A_P: Failed to get authorization URL" +
" for: $siteUrl - ${e.message}"
)
_navigationEvent.emit(NavigationEvent.Error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class ApplicationPasswordLoginHelperTest : BaseUnitTest() {
val result = applicationPasswordLoginHelper.storeApplicationPasswordCredentialsFrom(testUriLogin)

assertFalse(result)
verify(siteStore).sites
verify(siteStore, times(2)).sites
verify(dispatcherWrapper, times(0)).updateApplicationPassword(any())
verify(dispatcherWrapper, times(0)).removeApplicationPassword(any())
}
Expand Down
Loading