Handle AnyError properly

pull/2/head
Michael Scoff 7 years ago
parent 6fdfe02541
commit 9a4f06adc0
  1. 10
      Trust/Extensions/Error.swift

@ -3,12 +3,13 @@
import Foundation import Foundation
import APIKit import APIKit
import JSONRPCKit import JSONRPCKit
import Result
extension Error { extension Error {
var prettyError: String { var prettyError: String {
switch self { switch self {
case let error as LocalizedError: case let error as AnyError:
return error.errorDescription ?? "An unknown error occurred." switch error.error {
case let error as APIKit.SessionTaskError: case let error as APIKit.SessionTaskError:
switch error { switch error {
case .connectionError(let error): case .connectionError(let error):
@ -25,6 +26,10 @@ extension Error {
default: return "Undefined error" default: return "Undefined error"
} }
} }
default: return error.description
}
case let error as LocalizedError:
return error.errorDescription ?? "An unknown error occurred."
case let error as NSError: case let error as NSError:
return error.localizedDescription return error.localizedDescription
default: default:
@ -35,3 +40,4 @@ extension Error {
var code: Int { return (self as NSError).code } var code: Int { return (self as NSError).code }
var domain: String { return (self as NSError).domain } var domain: String { return (self as NSError).domain }
} }

Loading…
Cancel
Save