If a response doesn't have a content-type header, throw UnknownFormatException instead of ParseException

This commit is contained in:
Shinokuni 2020-10-05 22:24:47 +02:00
parent ec53cbd683
commit 6874ef2452
2 changed files with 2 additions and 2 deletions

View File

@ -140,7 +140,7 @@ class LocalRSSDataSourceTest {
localRSSDataSource.queryRSSResource(url.toString(), null) localRSSDataSource.queryRSSResource(url.toString(), null)
} }
@Test(expected = ParseException::class) @Test(expected = UnknownFormatException::class)
fun noContentTypeTest() { fun noContentTypeTest() {
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)) mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK))

View File

@ -37,7 +37,7 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) {
return when { return when {
response.isSuccessful -> { response.isSuccessful -> {
val header = response.header(LibUtils.CONTENT_TYPE_HEADER) val header = response.header(LibUtils.CONTENT_TYPE_HEADER)
?: throw ParseException("Unable to get $url content-type") ?: throw UnknownFormatException("Unable to get $url content-type")
val contentType = LibUtils.parseContentType(header) val contentType = LibUtils.parseContentType(header)
?: throw ParseException("Unable to parse $url content-type") ?: throw ParseException("Unable to parse $url content-type")