I 'm consuming a REST API, When the call goes OK, this API return a 200 OK Header, Then in the body it can handle two different JSONs
{"Error": {
"code" = 1
"msg" = "some error message"
}
}
Or if the data send was correct, it returns
{"code" : {
"status" = "Your submission is ..."
"msg" = "It is happy"
"answer" = {...}
}
The problem is that, If I use json4s, I must known which case class to use, what should I do, Use Either[Error,Code]
, after converting the JValue to String and check if contains Error then Left(Error) o else Right(Code), which solution should I Take. I'm looking for a good solution, and maybe a correct explanation about that.
The problem of my aprrocach is that Dispatch gives me Either[String, JsValue]
so finally I will get Either[String,Either[Error,Code]], and it seems not a good object