Use `when` statement instead of `if`/ `else`

This commit is contained in:
Florian Renaud 2021-08-24 15:36:53 +02:00
parent b4979e0bfb
commit 07adc43481
1 changed files with 10 additions and 7 deletions

View File

@ -86,13 +86,16 @@ private fun toFailure(errorBody: ResponseBody?, httpCode: Int, globalErrorReceiv
val matrixError = matrixErrorAdapter.fromJson(errorBodyStr) val matrixError = matrixErrorAdapter.fromJson(errorBodyStr)
if (matrixError != null) { if (matrixError != null) {
if (matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank()) { when {
// Also send this error to the globalErrorReceiver, for a global management matrixError.code == MatrixError.M_CONSENT_NOT_GIVEN && !matrixError.consentUri.isNullOrBlank() -> {
globalErrorReceiver?.handleGlobalError(GlobalError.ConsentNotGivenError(matrixError.consentUri)) // Also send this error to the globalErrorReceiver, for a global management
} else if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */ globalErrorReceiver?.handleGlobalError(GlobalError.ConsentNotGivenError(matrixError.consentUri))
&& matrixError.code == MatrixError.M_UNKNOWN_TOKEN) { }
// Also send this error to the globalErrorReceiver, for a global management httpCode == HttpURLConnection.HTTP_UNAUTHORIZED /* 401 */
globalErrorReceiver?.handleGlobalError(GlobalError.InvalidToken(matrixError.isSoftLogout.orFalse())) && matrixError.code == MatrixError.M_UNKNOWN_TOKEN -> {
// Also send this error to the globalErrorReceiver, for a global management
globalErrorReceiver?.handleGlobalError(GlobalError.InvalidToken(matrixError.isSoftLogout.orFalse()))
}
} }
return Failure.ServerError(matrixError, httpCode) return Failure.ServerError(matrixError, httpCode)