Skip to content

Commit

Permalink
DBNetworkStackErrors are now "pretty" printable in debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
ch-one committed Nov 24, 2016
1 parent 34efb9b commit 82b544e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions DBNetworkStack/DBNetworkStackError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,32 @@ public enum DBNetworkStackError: Error {
}

}

extension DBNetworkStackError : CustomDebugStringConvertible {

public var debugDescription: String {
var result = ""

switch self {
case .unknownError:
result = "Unknown error"
case .unauthorized(let response):
result = "Authorization error: \(response)"
case .clientError(let response):
result = "Client error: \(response)"
case .serializationError(let description, let data):
result = "Serialization error: \(description)"
if let data = data, let string = String(data: data, encoding: String.Encoding.utf8) {
result.append("\n\tdata: \(string)")
}
case .requestError(let error):
result = "Request error: \(error)"
case .serverError(let response):
result = "Server error: \(response)"
case .missingBaseURL:
result = "Missing base url error"
}

return result
}
}

0 comments on commit 82b544e

Please sign in to comment.