Repository navigation
Version 5.0.0-alpha01
The next version of NetworkResponseAdapter is here! Here's a list of all the changes:
Sealed Interfaces
The NetworkResponse class is now based on sealed interfaces. This allows for more concise when expressions when you don't care about the specific type of the error:
when (networkResponse) {
is NetworkResponse.Success -> ...
is NetworkResponse.Error -> ...
}Raw Retrofit Responses
NetworkResponse.Success and NetworkResponse.ServerError now bundle the raw retrofit Response<S> object to allow for greater access to the response of the network request.
when (networkResponse) {
is NetworkResponse.Success -> {
val statusCode = networkResponse.response.code()
}
}We still supply code and headers properties as before to retain familiarity with the existing API design.
Handling Empty Response Bodies
In the current version of the library you have to use the Unit response type if you expected your server to respond without a body. This is fine when the API never returns a body, but causes problems if it sometimes returns a body and sometimes doesn't (200 vs 204 status code).
The bundled raw Retrofit responses provide a better way to handle this situation.
interface PostsService {
@GET("/")
suspend fun getPost(): NetworkResponse<Unit, ErrorResponse>
}
when (val postResponse = service.getPost()) {
is NetworkResponse.Success -> {
if (postResponse.code != 204) {
val rawBody = postResponse.response.rawBody()
// Manually parse the raw body to access the response
}
}
is NetworkResponse.Error -> { ... }
}Tests Overhaul & Migration to Kotest
This PR gets refactors the library's test suite to get rid of redundant and obscure tests, and replaces them with a streamlined test suite focused on publicly exposed functionality.
We've also finally moved away from the deprecated kotlintest artifacts to the new kotest libraries.
Remove Deprecated Classes
We've removed deprecated ways to instantiate adapter factory. The existing classes had been marked as deprecated for a long period, and I hope everyone has moved away from them.
Kotlin 1.6.0
Updated the language level to 1.6.0
Sample App
Add a module showing sample usage of the library using the kotlinx.serialization library.