Hello! Who may help with information about how to...
# ktor
m
Hello! Who may help with information about how to implement a “response wrapper” pattern in the ktor-client. For example, has a model object User.
Copy code
data User(name: String)
Response from server with a wrapper: Success response:
Copy code
{
  "data": {
    "name": "Mark Watney"
  },
  "error": null
}
Business error respose:
Copy code
{

 	"data": null
 	"error": { ... }
 }
In android I can use something like an interceptor or an adapter in library like Retrofit, but what about ktor-client?
m
Ktor has a JsonFeature that can parse the response for you
m
There is no problem with json, a problem with a common data/error response. Now I am seeing Feature in ktor-client, maybe it will help me intercept server response and unwrap it.
m
Why don't you do
@Serializable Wrapper<T>(val data: T, val error: Error)
N
m
m
I see. Upvoted.