# 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)
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://appsecurity.gitbook.io/offensive/programming/android/frameworks/retrofit-okhttp/example-usage/parse-error-body.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
