You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/docs/special-cases.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,3 +31,19 @@ val retrofit = Retrofit.Builder()
31
31
.baseUrl("...")
32
32
.build()
33
33
```
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 classUnknownError(
43
+
valerror:Throwable,
44
+
valcode:Int? = null,
45
+
valheaders: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