This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Complex HTTP Errors Signed-off-by: d067928 <jakob.moeller@sap.com> * Correct Boolean Logic for Client/Server Error Check Signed-off-by: d067928 <jakob.moeller@sap.com> * Moved error handling of submission flow to CwaWebExceptions (#220) Co-authored-by: Kolya Opahle <k.opahle@sap.com>
- Loading branch information
1 parent
56e35c7
commit 16f016a
Showing
15 changed files
with
231 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
...na-Warn-App/src/main/java/de/rki/coronawarnapp/exception/SubmissionTanInvalidException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/TestAlreadyPairedException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/TestPairingInvalidException.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/WebRequestException.kt
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/exception/http/CwaWebException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package de.rki.coronawarnapp.exception.http | ||
|
||
import java.io.IOException | ||
|
||
open class CwaWebException(statusCode: Int) : IOException( | ||
"error during web request, http status $statusCode" | ||
) | ||
|
||
open class CwaServerError(val statusCode: Int) : CwaWebException(statusCode) { | ||
init { | ||
if (statusCode !in 500..599) | ||
throw IllegalArgumentException("a server error has to have code 5xx") | ||
} | ||
} | ||
|
||
open class CwaClientError(val statusCode: Int) : CwaWebException(statusCode) { | ||
init { | ||
if (statusCode !in 400..499) | ||
throw IllegalArgumentException("a client error has to have code 4xx") | ||
} | ||
} | ||
|
||
open class CwaSuccessResponseWithCodeMismatchNotSupportedError(val statusCode: Int) : CwaWebException(statusCode) | ||
open class CwaInformationalNotSupportedError(val statusCode: Int) : CwaWebException(statusCode) | ||
open class CwaRedirectNotSupportedError(val statusCode: Int) : CwaWebException(statusCode) | ||
|
||
class BadRequestException : CwaClientError(400) | ||
class UnauthorizedException : CwaClientError(401) | ||
class ForbiddenException : CwaClientError(403) | ||
class NotFoundException : CwaClientError(404) | ||
class ConflictException : CwaClientError(409) | ||
class GoneException : CwaClientError(410) | ||
class UnsupportedMediaTypeException : CwaClientError(415) | ||
class TooManyRequestsException : CwaClientError(429) | ||
|
||
class InternalServerErrorException : CwaServerError(500) | ||
class NotImplementedException : CwaServerError(501) | ||
class BadGatewayException : CwaServerError(502) | ||
class ServiceUnavailableException : CwaServerError(503) | ||
class GatewayTimeoutException : CwaServerError(504) | ||
class HTTPVersionNotSupported : CwaServerError(505) | ||
class NetworkAuthenticationRequiredException : CwaServerError(511) | ||
class NetworkReadTimeoutException : CwaServerError(598) | ||
class NetworkConnectTimeoutException : CwaServerError(599) |
64 changes: 64 additions & 0 deletions
64
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/http/HttpErrorParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package de.rki.coronawarnapp.http | ||
|
||
import de.rki.coronawarnapp.exception.http.BadGatewayException | ||
import de.rki.coronawarnapp.exception.http.CwaWebException | ||
import de.rki.coronawarnapp.exception.http.BadRequestException | ||
import de.rki.coronawarnapp.exception.http.ConflictException | ||
import de.rki.coronawarnapp.exception.http.CwaClientError | ||
import de.rki.coronawarnapp.exception.http.CwaInformationalNotSupportedError | ||
import de.rki.coronawarnapp.exception.http.CwaRedirectNotSupportedError | ||
import de.rki.coronawarnapp.exception.http.CwaServerError | ||
import de.rki.coronawarnapp.exception.http.CwaSuccessResponseWithCodeMismatchNotSupportedError | ||
import de.rki.coronawarnapp.exception.http.ForbiddenException | ||
import de.rki.coronawarnapp.exception.http.GatewayTimeoutException | ||
import de.rki.coronawarnapp.exception.http.GoneException | ||
import de.rki.coronawarnapp.exception.http.HTTPVersionNotSupported | ||
import de.rki.coronawarnapp.exception.http.InternalServerErrorException | ||
import de.rki.coronawarnapp.exception.http.NetworkAuthenticationRequiredException | ||
import de.rki.coronawarnapp.exception.http.NetworkConnectTimeoutException | ||
import de.rki.coronawarnapp.exception.http.NetworkReadTimeoutException | ||
import de.rki.coronawarnapp.exception.http.NotFoundException | ||
import de.rki.coronawarnapp.exception.http.NotImplementedException | ||
import de.rki.coronawarnapp.exception.http.ServiceUnavailableException | ||
import de.rki.coronawarnapp.exception.http.TooManyRequestsException | ||
import de.rki.coronawarnapp.exception.http.UnauthorizedException | ||
import de.rki.coronawarnapp.exception.http.UnsupportedMediaTypeException | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
class HttpErrorParser : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
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() | ||
429 -> throw TooManyRequestsException() | ||
500 -> throw InternalServerErrorException() | ||
501 -> throw NotImplementedException() | ||
502 -> throw BadGatewayException() | ||
503 -> throw ServiceUnavailableException() | ||
504 -> throw GatewayTimeoutException() | ||
505 -> throw HTTPVersionNotSupported() | ||
511 -> throw NetworkAuthenticationRequiredException() | ||
598 -> throw NetworkReadTimeoutException() | ||
599 -> throw NetworkConnectTimeoutException() | ||
else -> { | ||
if (code in 100..199) throw CwaInformationalNotSupportedError(code) | ||
if (code in 200..299) throw CwaSuccessResponseWithCodeMismatchNotSupportedError(code) | ||
if (code in 300..399) throw CwaRedirectNotSupportedError(code) | ||
if (code in 400..499) throw CwaClientError(code) | ||
if (code in 500..599) throw CwaServerError(code) | ||
throw CwaWebException(code) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.