Skip to content

Commit f56df54

Browse files
committed
feat: Update docs
1 parent 1ced472 commit f56df54

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/docs/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data class DetailsError(
3030
)
3131

3232
interface Api {
33-
@Get("/details)
33+
@Get("/details")
3434
suspend fun details(): NetworkResponse<DetailsResponse, DetailsError>
3535
}
3636

docs/docs/docs/special-cases.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,19 @@ val retrofit = Retrofit.Builder()
3131
.baseUrl("...")
3232
.build()
3333
```
34+
35+
## Status code and Headers in `NetworkResponse.UnknownError`
36+
37+
Network requests that result in a `NetworkResponse.UnknownError` can still convey useful information through their headers and status code. Unfortunately, it is not always possible to extract these values from a failed request.
38+
39+
Therefore, the `NetworkResponse.UnknownError` class contains nullable fields for the status code and headers. These fields are populated if their values can be extract from a failed request.
40+
41+
```kotlin
42+
data class UnknownError(
43+
val error: Throwable,
44+
val code: Int? = null,
45+
val headers: Headers? = null,
46+
) : NetworkResponse<Nothing, Nothing>()
47+
```
48+
49+
It is possible to extract this information from a failed request in most cases. However, if the server responds with a successful status code (200 <= code < 300) and an invalid body (which can not be parsed correctly), Retrofit assumes the network request failed. It forwards only the raised error and the original call to the registered call adapter, and thus all information about the response is lost resulting in a `NetworkResponse.UnknownError` with null `code` and `headers`.

0 commit comments

Comments
 (0)