I am trying to decode the error as follows, most of the error that I am handling in array format [String]
, but in few cases the error is not in array format, just a String
.
If error comes in array format name comes as errors
, but if it is string format then it comes as error
. How could I handle this scenario?
How could I able to handle this scenario?
struct CustomError: Codable {
let errors: [String]
}
private func errorDecoding(data : Data) {
let decoder = JSONDecoder()
do {
let errorData = try decoder.decode(CustomError.self, from: data)
} catch {
// TODO
}
}