> For the complete documentation index, see [llms.txt](https://appsecurity.gitbook.io/offensive/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://appsecurity.gitbook.io/offensive/programming/android/frameworks/retrofit-okhttp/example-usage/parse-error-body.md).

# Parse error body

Как парсить ошибки в ответе (4xx, 5xx)

```kotlin
val authApi = ControllerApi().getAuthApi()
val refreshTokenReq = authApi.register(user)

refreshTokenReq.enqueue(object : Callback<...>) {
    override fun onResponse(call: ..., response: ...) {
        if (response.isSuccessful) {
            ...
        }
        else {
            val gson = Gson()
            val type = object : TypeToken<MyErrorData>(){}.type
            val myErrorBody: MyErrorData? = gson.fromJson(response.errorBody()!!.charStream(), type)
        }
    }
}
```
