Change exception hierarchy

This commit is contained in:
Mikołaj Pich 2020-10-15 11:53:38 +02:00
parent 86b76c8c6a
commit e769c833ad
2 changed files with 5 additions and 3 deletions

View file

@ -1,3 +1,3 @@
package io.github.wulkanowy.sdk.scrapper.exception package io.github.wulkanowy.sdk.scrapper.exception
class ServiceUnavailableException internal constructor(message: String) : ScrapperException(message) class ServiceUnavailableException internal constructor(message: String) : VulcanException(message)

View file

@ -1,6 +1,7 @@
package io.github.wulkanowy.sdk.scrapper.interceptor package io.github.wulkanowy.sdk.scrapper.interceptor
import io.github.wulkanowy.sdk.scrapper.exception.ScrapperException import io.github.wulkanowy.sdk.scrapper.exception.ScrapperException
import io.github.wulkanowy.sdk.scrapper.exception.ServiceUnavailableException
import io.github.wulkanowy.sdk.scrapper.exception.VulcanException import io.github.wulkanowy.sdk.scrapper.exception.VulcanException
import io.github.wulkanowy.sdk.scrapper.login.NotLoggedInException import io.github.wulkanowy.sdk.scrapper.login.NotLoggedInException
import okhttp3.Interceptor import okhttp3.Interceptor
@ -15,8 +16,9 @@ class HttpErrorInterceptor : Interceptor {
return when (response.code()) { return when (response.code()) {
429 -> throw NotLoggedInException(response.body()?.string() ?: response.message()) 429 -> throw NotLoggedInException(response.body()?.string() ?: response.message())
in 400..499 -> throw ScrapperException(response.code().toString() + ": " + response.message()) 404 -> throw ScrapperException(response.code().toString() + ": " + response.message())
in 500..599 -> throw VulcanException(response.code().toString() + ": " + response.message()) in 400..499 -> throw VulcanException(response.code().toString() + ": " + response.message())
in 500..599 -> throw ServiceUnavailableException(response.code().toString() + ": " + response.message())
else -> response else -> response
} }
} }