mirror of
https://github.com/tappollo/WWDC.git
synced 2026-01-12 22:45:32 +08:00
40 lines
824 B
Swift
40 lines
824 B
Swift
//
|
|
// Resource+Error.swift
|
|
// WWDC
|
|
//
|
|
// Created by Guilherme Rambo on 21/02/17.
|
|
// Copyright © 2017 Guilherme Rambo. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Siesta
|
|
|
|
public enum APIError: Error {
|
|
case http(Error)
|
|
case adapter
|
|
case unknown
|
|
|
|
public var localizedDescription: String {
|
|
switch self {
|
|
case .http(let error):
|
|
return error.localizedDescription
|
|
case .adapter:
|
|
return "Unable to process the data returned by the server"
|
|
case .unknown:
|
|
return "An unknown networking error occurred"
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Resource {
|
|
|
|
var error: APIError {
|
|
if let underlyingError = self.latestError {
|
|
return .http(underlyingError)
|
|
} else {
|
|
return .unknown
|
|
}
|
|
}
|
|
|
|
}
|