Open jgongo opened 7 years ago
It sounds interesting, but it's hard to say without more concrete thoughts. What kind of generic methods?
The idea would be to substitute BackendError
with a generic inheriting from Decodable
, so you can invoke that property/method passing the type of the error response and get the error returned by the server. It would be similar to the map
method, where you pass the Decodable
type to use when decoding the success response as a parameter.
I've been recently faced with getting the error information from the server when filtering successful response codes. As I explain in this StackOverflow response, I think the easiest and cleanest way is to extend
MoyaError
to provide access to the body response, using code like this:so you can later retrieve the information in this way:
When doing this I thought it may be interesting to include generic methods in the
Moya
framework itself, so users of the framework don't have to manually invoke mapping methods on the response included in theMoyaError
. What do you think?