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 ...@@ -27,30 +27,31 @@ import de.rki.coronawarnapp.exception.http.UnsupportedMediaTypeException
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
import java.net.UnknownHostException import java.net.UnknownHostException
import javax.net.ssl.HttpsURLConnection
class HttpErrorParser : Interceptor { class HttpErrorParser : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response { override fun intercept(chain: Interceptor.Chain): Response {
try { try {
val response = chain.proceed(chain.request()) val response = chain.proceed(chain.request())
return when (val code = response.code) { return when (val code = response.code) {
200 -> response HttpsURLConnection.HTTP_OK -> response
201 -> response HttpsURLConnection.HTTP_CREATED -> response
202 -> response HttpsURLConnection.HTTP_ACCEPTED -> response
204 -> response HttpsURLConnection.HTTP_NO_CONTENT -> response
400 -> throw BadRequestException() HttpsURLConnection.HTTP_BAD_REQUEST -> throw BadRequestException()
401 -> throw UnauthorizedException() HttpsURLConnection.HTTP_UNAUTHORIZED -> throw UnauthorizedException()
403 -> throw ForbiddenException() HttpsURLConnection.HTTP_FORBIDDEN -> throw ForbiddenException()
404 -> throw NotFoundException() HttpsURLConnection.HTTP_NOT_FOUND -> throw NotFoundException()
409 -> throw ConflictException() HttpsURLConnection.HTTP_CONFLICT -> throw ConflictException()
410 -> throw GoneException() HttpsURLConnection.HTTP_GONE -> throw GoneException()
415 -> throw UnsupportedMediaTypeException() HttpsURLConnection.HTTP_UNSUPPORTED_TYPE -> throw UnsupportedMediaTypeException()
429 -> throw TooManyRequestsException() 429 -> throw TooManyRequestsException()
500 -> throw InternalServerErrorException() HttpsURLConnection.HTTP_INTERNAL_ERROR -> throw InternalServerErrorException()
501 -> throw NotImplementedException() HttpsURLConnection.HTTP_NOT_IMPLEMENTED -> throw NotImplementedException()
502 -> throw BadGatewayException() HttpsURLConnection.HTTP_BAD_GATEWAY -> throw BadGatewayException()
503 -> throw ServiceUnavailableException() HttpsURLConnection.HTTP_UNAVAILABLE -> throw ServiceUnavailableException()
504 -> throw GatewayTimeoutException() HttpsURLConnection.HTTP_GATEWAY_TIMEOUT -> throw GatewayTimeoutException()
505 -> throw HTTPVersionNotSupported() HttpsURLConnection.HTTP_VERSION -> throw HTTPVersionNotSupported()
511 -> throw NetworkAuthenticationRequiredException() 511 -> throw NetworkAuthenticationRequiredException()
598 -> throw NetworkReadTimeoutException() 598 -> throw NetworkReadTimeoutException()
599 -> throw NetworkConnectTimeoutException() 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