diff --git a/core/actionresult/src/main/kotlin/nl/q42/template/actionresult/data/ActionResultMapper.kt b/core/actionresult/src/main/kotlin/nl/q42/template/actionresult/data/ActionResultMapper.kt index 3206cf8..97f144a 100644 --- a/core/actionresult/src/main/kotlin/nl/q42/template/actionresult/data/ActionResultMapper.kt +++ b/core/actionresult/src/main/kotlin/nl/q42/template/actionresult/data/ActionResultMapper.kt @@ -47,26 +47,29 @@ private fun NetworkResponse.networkResponseToActi } is NetworkResponse.NetworkError -> // Used to represent connectivity errors - when (this.error) { + { + when (val error = this.error) { is UnknownHostException, is ConnectException, is SocketTimeoutException -> { - ActionResult.Error.NetworkError(this.error) + ActionResult.Error.NetworkError(error) } is EOFException -> { // let's log this error, includes an incomplete json response - ActionResult.Error.Other(this.error) + ActionResult.Error.Other(error) } - else -> ActionResult.Error.Other(this.error) + else -> ActionResult.Error.Other(error) } + } is NetworkResponse.UnknownError -> { val statusCode = this.code val errorMessage = "Received NetworkResponse.UnknownError with response code $statusCode and header ${this.headers}" - val exception = IOException(errorMessage, this.error) - Napier.w(this.error) { "NetworkResponse.UnknownError" } + val error = this.error + val exception = IOException(errorMessage, error) + Napier.w(error) { "NetworkResponse.UnknownError" } when { - this.error is SerializationException -> { // (usually json) parsing error - ActionResult.Error.InvalidErrorResponse(this.error as SerializationException) + error is SerializationException -> { // (usually json) parsing error + ActionResult.Error.InvalidErrorResponse(error) } statusCode == null -> { diff --git a/core/network/src/main/kotlin/nl/q42/template/core/network/di/NetworkModule.kt b/core/network/src/main/kotlin/nl/q42/template/core/network/di/NetworkModule.kt index 9607b64..800babd 100644 --- a/core/network/src/main/kotlin/nl/q42/template/core/network/di/NetworkModule.kt +++ b/core/network/src/main/kotlin/nl/q42/template/core/network/di/NetworkModule.kt @@ -43,6 +43,7 @@ internal class NetworkModule { ): Retrofit { val contentType = "application/json".toMediaType() + // When the server adds new fields to the response, we don't want to crash val json = Json { ignoreUnknownKeys = true } return Retrofit.Builder() diff --git a/data/user/src/main/kotlin/nl/q42/template/data/user/remote/model/UserDTO.kt b/data/user/src/main/kotlin/nl/q42/template/data/user/remote/model/UserDTO.kt index 2a05977..24c06df 100644 --- a/data/user/src/main/kotlin/nl/q42/template/data/user/remote/model/UserDTO.kt +++ b/data/user/src/main/kotlin/nl/q42/template/data/user/remote/model/UserDTO.kt @@ -9,11 +9,11 @@ import kotlinx.serialization.Serializable */ @Serializable -data class UserDTO( +internal data class UserDTO( val args: ArgsDTO ) @Serializable -data class ArgsDTO( +internal data class ArgsDTO( val email: String )