I'm using Alamofire and its Combine helpers to do a simple network request as follows:
class AlamofireClient {
func getData<T: Decodable>(request: URLRequestConvertible) -> AnyPublisher<T, APIError> {
AF.request(request)
.validate()
.publishDecodable(type: T.self)
.value()
.mapError(APIError.init(error:))
.eraseToAnyPublisher()
}
}
enum APIError: Error {
init(error: AFError) {
self = .network
}
case network
case custom(Int, String, String)
var message: String {
switch self {
case .network:
return "Network Error"
case .custom(let code, let message, let technicalMessage):
return "Custom error info are: \(code) -- \(message) -- \(technicalMessage)"
}
}
}
I'm stuck at extracting the custom error info that is returned from the server, which's in my case has 3 items: code, message and technicalMessage.