diff --git a/app/src/main/java/io/heckel/ntfy/db/Database.kt b/app/src/main/java/io/heckel/ntfy/db/Database.kt index 278f2482..5e9079da 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Database.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Database.kt @@ -78,12 +78,11 @@ enum class ConnectionState { */ data class ConnectionDetails( val state: ConnectionState = ConnectionState.NOT_APPLICABLE, - val error: String? = null, - val throwable: Throwable? = null, + val error: Throwable? = null, val nextRetryTime: Long = 0L ) { fun getStackTraceString(): String { - return throwable?.stackTraceToString() ?: "" + return error?.stackTraceToString() ?: "" } fun hasError(): Boolean { diff --git a/app/src/main/java/io/heckel/ntfy/db/Repository.kt b/app/src/main/java/io/heckel/ntfy/db/Repository.kt index ba631cae..f5f0aeac 100644 --- a/app/src/main/java/io/heckel/ntfy/db/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/db/Repository.kt @@ -546,8 +546,8 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) ) } - fun updateConnectionDetails(baseUrl: String, state: ConnectionState, error: String? = null, throwable: Throwable? = null, nextRetryTime: Long = 0L) { - val details = ConnectionDetails(state, error, throwable, nextRetryTime) + fun updateConnectionDetails(baseUrl: String, state: ConnectionState, error: Throwable? = null, nextRetryTime: Long = 0L) { + val details = ConnectionDetails(state, error, nextRetryTime) val current = connectionDetails[baseUrl] if (current != details) { if (state == ConnectionState.NOT_APPLICABLE && error == null) { @@ -556,7 +556,7 @@ class Repository(private val sharedPrefs: SharedPreferences, database: Database) connectionDetails[baseUrl] = details } connectionDetailsLiveData.postValue(connectionDetails.toMap()) - Log.d(TAG, "Connection details updated for $baseUrl: state=$state, error=$error, nextRetry=$nextRetryTime") + Log.d(TAG, "Connection details updated for $baseUrl: state=$state, error=${error?.message}, nextRetry=$nextRetryTime") } } diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index 3c31d7b5..697b03d9 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -309,8 +309,7 @@ class SubscriberService : Service() { val subscriptionId = subscriptionIds.firstOrNull() ?: return val subscription = repository.getSubscription(subscriptionId) ?: return val baseUrl = subscription.baseUrl - val errorMessage = throwable?.message - repository.updateConnectionDetails(baseUrl, state, errorMessage, throwable, nextRetryTime) + repository.updateConnectionDetails(baseUrl, state, throwable, nextRetryTime) } private fun onNotificationReceived(subscription: Subscription, notification: io.heckel.ntfy.db.Notification) { diff --git a/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt index 6c23e6fd..8bb1952d 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/ConnectionErrorFragment.kt @@ -164,7 +164,7 @@ class ConnectionErrorFragment : DialogFragment() { private fun updateErrorDisplay() { val details = selectedBaseUrl?.let { connectionDetails[it] } if (details != null && details.hasError()) { - errorTextView.text = details.error + errorTextView.text = details.error?.message ?: getString(R.string.connection_error_dialog_no_error) stackTraceTextView.text = details.getStackTraceString().ifEmpty { getString(R.string.connection_error_dialog_no_stack_trace) } @@ -202,7 +202,7 @@ class ConnectionErrorFragment : DialogFragment() { val details = connectionDetails[baseUrl] ?: return val text = buildString { appendLine("Server: $baseUrl") - appendLine("Error: ${details.error}") + appendLine("Error: ${details.error?.message ?: "Unknown error"}") appendLine() appendLine("Stack trace:") append(details.getStackTraceString().ifEmpty { "No stack trace available" })