Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ninovanhooff committed Dec 29, 2023
1 parent af71d5c commit 59a2635
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,29 @@ private fun <T : Any> NetworkResponse<T, ApiErrorResponse>.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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 59a2635

Please sign in to comment.