Imporve logs.
This commit is contained in:
parent
90352bd1ad
commit
35b019318e
1 changed files with 9 additions and 5 deletions
|
|
@ -34,29 +34,33 @@ class DefaultUnifiedPushGatewayResolver @Inject constructor(
|
||||||
private val unifiedPushApiFactory: UnifiedPushApiFactory,
|
private val unifiedPushApiFactory: UnifiedPushApiFactory,
|
||||||
private val coroutineDispatchers: CoroutineDispatchers,
|
private val coroutineDispatchers: CoroutineDispatchers,
|
||||||
) : UnifiedPushGatewayResolver {
|
) : UnifiedPushGatewayResolver {
|
||||||
|
private val logger = Timber.tag("DefaultUnifiedPushGatewayResolver")
|
||||||
|
|
||||||
override suspend fun getGateway(endpoint: String): String {
|
override suspend fun getGateway(endpoint: String): String {
|
||||||
val url = tryOrNull(
|
val url = tryOrNull(
|
||||||
onError = { Timber.d(it, "Cannot parse endpoint as an URL") }
|
onError = { logger.d(it, "Cannot parse endpoint as an URL") }
|
||||||
) {
|
) {
|
||||||
URL(endpoint)
|
URL(endpoint)
|
||||||
}
|
}
|
||||||
return if (url == null) {
|
return if (url == null) {
|
||||||
Timber.d("Using default gateway")
|
logger.d("Using default gateway")
|
||||||
UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
|
UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL
|
||||||
} else {
|
} else {
|
||||||
val port = if (url.port != -1) ":${url.port}" else ""
|
val port = if (url.port != -1) ":${url.port}" else ""
|
||||||
val customBase = "${url.protocol}://${url.host}$port"
|
val customBase = "${url.protocol}://${url.host}$port"
|
||||||
val customUrl = "$customBase/_matrix/push/v1/notify"
|
val customUrl = "$customBase/_matrix/push/v1/notify"
|
||||||
Timber.i("Testing $customUrl")
|
logger.i("Testing $customUrl")
|
||||||
return withContext(coroutineDispatchers.io) {
|
return withContext(coroutineDispatchers.io) {
|
||||||
val api = unifiedPushApiFactory.create(customBase)
|
val api = unifiedPushApiFactory.create(customBase)
|
||||||
try {
|
try {
|
||||||
val discoveryResponse = api.discover()
|
val discoveryResponse = api.discover()
|
||||||
if (discoveryResponse.unifiedpush.gateway == "matrix") {
|
if (discoveryResponse.unifiedpush.gateway == "matrix") {
|
||||||
Timber.d("Using custom gateway")
|
logger.d("The endpoint seems to be a valid UnifiedPush gateway")
|
||||||
|
} else {
|
||||||
|
logger.e("The endpoint does not seem to be a valid UnifiedPush gateway")
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
Timber.tag("UnifiedPushHelper").e(throwable)
|
logger.e(throwable, "Error checking for UnifiedPush endpoint")
|
||||||
}
|
}
|
||||||
// Always return the custom url.
|
// Always return the custom url.
|
||||||
customUrl
|
customUrl
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue