Use HttpException in LocalRSSDataSource

This commit is contained in:
Shinokuni 2023-08-01 21:54:18 +02:00
parent 35ad5dfbc4
commit 4697219312
2 changed files with 5 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import com.gitlab.mvysny.konsumexml.konsumeXml
import com.readrops.api.localfeed.json.JSONFeedAdapter
import com.readrops.api.utils.ApiUtils
import com.readrops.api.utils.AuthInterceptor
import com.readrops.api.utils.exceptions.HttpException
import com.readrops.api.utils.exceptions.ParseException
import com.readrops.api.utils.exceptions.UnknownFormatException
import com.readrops.db.entities.Feed
@ -32,7 +33,7 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) : KoinComponent {
* @param headers request headers
* @return a Feed object with its items
*/
@Throws(ParseException::class, UnknownFormatException::class, NetworkErrorException::class, IOException::class)
@Throws(ParseException::class, UnknownFormatException::class, HttpException::class, IOException::class)
@WorkerThread
fun queryRSSResource(url: String, headers: Headers?): Pair<Feed, List<Item>>? {
get<AuthInterceptor>().credentials = null
@ -46,7 +47,7 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) : KoinComponent {
pair
}
response.code == HttpURLConnection.HTTP_NOT_MODIFIED -> null
else -> throw NetworkErrorException("$url returned ${response.code} code : ${response.message}")
else -> throw HttpException(response)
}
}

View File

@ -5,6 +5,7 @@ import com.readrops.api.TestUtils
import com.readrops.api.apiModule
import com.readrops.api.utils.ApiUtils
import com.readrops.api.utils.AuthInterceptor
import com.readrops.api.utils.exceptions.HttpException
import com.readrops.api.utils.exceptions.ParseException
import com.readrops.api.utils.exceptions.UnknownFormatException
import junit.framework.TestCase.*
@ -149,7 +150,7 @@ class LocalRSSDataSourceTest : KoinTest {
assertNull(pair)
}
@Test(expected = NetworkErrorException::class)
@Test(expected = HttpException::class)
fun response404Test() {
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND))