Skip to content

Instantly share code, notes, and snippets.

@mergesort
Created January 21, 2015 20:07
Show Gist options
  • Save mergesort/4d0184fb6ac9d803f8be to your computer and use it in GitHub Desktop.
Save mergesort/4d0184fb6ac9d803f8be to your computer and use it in GitHub Desktop.
protocol APIError {
var domain: String { get }
var code: ErrorCode { get }
}
struct UnexpectedAPIError : APIError {
let domain = "An unexpected error occurred"
let code = ErrorCode.UnexpectedAPIError
}
extension NSError {
class func APIError<T: APIError>(error: T) -> NSError {
return NSError(domain: error.domain, code: error.code.rawValue, userInfo: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment