Reputation: 1461
We are using codeble in our API management layer, we are trying to set up models with codables and decodables.
In one case we have error in our response model. How can we handle that?
Here is the sample code:
struct Address : Codable {
var street: String
var zip: String
var city: String
var error: Error
private enum CodingKeys : String, CodingKey {
case street, zip = "zip_code", city, state
}
}
We are getting below error:
Cannot automatically synthesize 'Encodable' because 'Error' does not conform to 'Encodable'
How can we handle error type in codables?
Upvotes: 0
Views: 1761
Reputation: 273
Why do you need an Error property in this struct ?
You can send your Address model if api response is success, you can send Error model if api response is failure, also you can create your own error model inherited from the Error.
Upvotes: 0