Skip to content

//NetworkResponseAdapter/com.haroldadmin.cnradapter/NetworkResponse

NetworkResponse

[jvm]\ interface NetworkResponse<S, E>

Represents the result of a network request made using Retrofit. It can be either in a success state or an error state, depending on the result of the request.

S represents the deserialized body of a successful response. E represents the deserialized body of an unsuccessful response.

A network request is considered to be successful if it received a 2xx response code, and unsuccessful otherwise.

If the network request was successful and Retrofit successfully deserialized the body, the NetworkResponse is NetworkResponse.Success. If you do not expect a successful response to contain a body, you must specify S as Unit or use CompletableResponse.

If the network request failed due to:

Types

Name Summary
Error [jvm]
interface Error<S, E> : NetworkResponse<S, E>
The result of a failed network request.
NetworkError [jvm]
data class NetworkError<S, E>(error: IOException) : NetworkResponse.Error<S, E>
The result of a network connectivity error
ServerError [jvm]
data class ServerError<S, E>(body: E?, response: Response<*>?) : NetworkResponse.Error<S, E>
The result of a non 2xx response to a network request.
Success [jvm]
data class Success<S, E>(body: S, response: Response<*>) : NetworkResponse<S, E>
The result of a successful network request.
UnknownError [jvm]
data class UnknownError<S, E>(error: Throwable, response: Response<*>?) : NetworkResponse.Error<S, E>
Result of an unknown error during a network request (e.g. Serialization errors)

Inheritors

Name
Success
Error

Extensions

Name Summary
invoke [jvm]
operator fun <T : Any, U : Any> NetworkResponse<T, U>.invoke(): T?
Overloaded invoke operator to get the successful body or null in NetworkResponse class