Skip to content
Snippets Groups Projects
Unverified Commit d7a1ceaa authored by Leo's avatar Leo Committed by GitHub
Browse files

#918 Fix Hard coded by Http Status code judgment. (#919)


Co-authored-by: default avatarMatthias Urhahn <darken@darken.eu>
parent 7bed1d48
No related branches found
No related tags found
No related merge requests found
......@@ -27,30 +27,31 @@ import de.rki.coronawarnapp.exception.http.UnsupportedMediaTypeException
import okhttp3.Interceptor
import okhttp3.Response
import java.net.UnknownHostException
import javax.net.ssl.HttpsURLConnection
class HttpErrorParser : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
try {
val response = chain.proceed(chain.request())
return when (val code = response.code) {
200 -> response
201 -> response
202 -> response
204 -> response
400 -> throw BadRequestException()
401 -> throw UnauthorizedException()
403 -> throw ForbiddenException()
404 -> throw NotFoundException()
409 -> throw ConflictException()
410 -> throw GoneException()
415 -> throw UnsupportedMediaTypeException()
HttpsURLConnection.HTTP_OK -> response
HttpsURLConnection.HTTP_CREATED -> response
HttpsURLConnection.HTTP_ACCEPTED -> response
HttpsURLConnection.HTTP_NO_CONTENT -> response
HttpsURLConnection.HTTP_BAD_REQUEST -> throw BadRequestException()
HttpsURLConnection.HTTP_UNAUTHORIZED -> throw UnauthorizedException()
HttpsURLConnection.HTTP_FORBIDDEN -> throw ForbiddenException()
HttpsURLConnection.HTTP_NOT_FOUND -> throw NotFoundException()
HttpsURLConnection.HTTP_CONFLICT -> throw ConflictException()
HttpsURLConnection.HTTP_GONE -> throw GoneException()
HttpsURLConnection.HTTP_UNSUPPORTED_TYPE -> throw UnsupportedMediaTypeException()
429 -> throw TooManyRequestsException()
500 -> throw InternalServerErrorException()
501 -> throw NotImplementedException()
502 -> throw BadGatewayException()
503 -> throw ServiceUnavailableException()
504 -> throw GatewayTimeoutException()
505 -> throw HTTPVersionNotSupported()
HttpsURLConnection.HTTP_INTERNAL_ERROR -> throw InternalServerErrorException()
HttpsURLConnection.HTTP_NOT_IMPLEMENTED -> throw NotImplementedException()
HttpsURLConnection.HTTP_BAD_GATEWAY -> throw BadGatewayException()
HttpsURLConnection.HTTP_UNAVAILABLE -> throw ServiceUnavailableException()
HttpsURLConnection.HTTP_GATEWAY_TIMEOUT -> throw GatewayTimeoutException()
HttpsURLConnection.HTTP_VERSION -> throw HTTPVersionNotSupported()
511 -> throw NetworkAuthenticationRequiredException()
598 -> throw NetworkReadTimeoutException()
599 -> throw NetworkConnectTimeoutException()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment