Fix push gateway with some push provider (Sunup/autopush) (#5741)
* Add more HTTP response code returning NoMatrixGateway Fix Push notifications with Mozilla's autopush that returns 406 * Update gateway resolver tests to match new known errors
This commit is contained in:
parent
6bdb4d1ad4
commit
3cbdc97cdd
2 changed files with 44 additions and 3 deletions
|
|
@ -64,8 +64,9 @@ class DefaultUnifiedPushGatewayResolver(
|
||||||
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
||||||
}
|
}
|
||||||
} catch (throwable: Throwable) {
|
} catch (throwable: Throwable) {
|
||||||
if ((throwable as? HttpException)?.code() == HttpURLConnection.HTTP_NOT_FOUND) {
|
val code = (throwable as? HttpException)?.code()
|
||||||
Timber.tag(loggerTag.value).i("Checking for UnifiedPush endpoint yielded 404, using fallback")
|
if (code in NoMatrixGatewayResp) {
|
||||||
|
Timber.tag(loggerTag.value).i("Checking for UnifiedPush endpoint yielded $code, using fallback")
|
||||||
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
UnifiedPushGatewayResolverResult.NoMatrixGateway
|
||||||
} else {
|
} else {
|
||||||
Timber.tag(loggerTag.value).e(throwable, "Error checking for UnifiedPush endpoint")
|
Timber.tag(loggerTag.value).e(throwable, "Error checking for UnifiedPush endpoint")
|
||||||
|
|
@ -75,4 +76,14 @@ class DefaultUnifiedPushGatewayResolver(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val NoMatrixGatewayResp = listOf<Int>(
|
||||||
|
HttpURLConnection.HTTP_UNAUTHORIZED,
|
||||||
|
HttpURLConnection.HTTP_FORBIDDEN,
|
||||||
|
HttpURLConnection.HTTP_NOT_FOUND,
|
||||||
|
HttpURLConnection.HTTP_BAD_METHOD,
|
||||||
|
HttpURLConnection.HTTP_NOT_ACCEPTABLE
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class DefaultUnifiedPushGatewayResolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when a custom url is forbidden (403), Error is returned`() = runTest {
|
fun `when a custom url is forbidden (403), NoMatrixGateway is returned`() = runTest {
|
||||||
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
discoveryResponse = {
|
discoveryResponse = {
|
||||||
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_FORBIDDEN, "".toResponseBody()))
|
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_FORBIDDEN, "".toResponseBody()))
|
||||||
|
|
@ -130,6 +130,36 @@ class DefaultUnifiedPushGatewayResolverTest {
|
||||||
)
|
)
|
||||||
val result = sut.getGateway("http://custom.url")
|
val result = sut.getGateway("http://custom.url")
|
||||||
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||||
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.NoMatrixGateway)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when a custom url is not acceptable (406), NoMatrixGateway is returned`() = runTest {
|
||||||
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
|
discoveryResponse = {
|
||||||
|
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_NOT_ACCEPTABLE, "".toResponseBody()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||||
|
unifiedPushApiFactory = unifiedPushApiFactory
|
||||||
|
)
|
||||||
|
val result = sut.getGateway("http://custom.url")
|
||||||
|
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||||
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.NoMatrixGateway)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when a custom url is internal error (500), Error is returned`() = runTest {
|
||||||
|
val unifiedPushApiFactory = FakeUnifiedPushApiFactory(
|
||||||
|
discoveryResponse = {
|
||||||
|
throw HttpException(Response.error<Unit>(HttpURLConnection.HTTP_INTERNAL_ERROR, "".toResponseBody()))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
val sut = createDefaultUnifiedPushGatewayResolver(
|
||||||
|
unifiedPushApiFactory = unifiedPushApiFactory
|
||||||
|
)
|
||||||
|
val result = sut.getGateway("http://custom.url")
|
||||||
|
assertThat(unifiedPushApiFactory.baseUrlParameter).isEqualTo("http://custom.url")
|
||||||
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
assertThat(result).isEqualTo(UnifiedPushGatewayResolverResult.Error("http://custom.url/_matrix/push/v1/notify"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue