implement errorDescription for OpenAIError
This commit is contained in:
@@ -9,6 +9,15 @@ public enum OpenAIError: Error {
|
|||||||
case decodingError(error: Error)
|
case decodingError(error: Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension OpenAIError: LocalizedError {
|
||||||
|
public var errorDescription: String? {
|
||||||
|
switch self {
|
||||||
|
case .genericError(let error), .decodingError(let error):
|
||||||
|
return error.localizedDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class OpenAISwift {
|
public class OpenAISwift {
|
||||||
fileprivate(set) var token: String?
|
fileprivate(set) var token: String?
|
||||||
fileprivate let config: Config
|
fileprivate let config: Config
|
||||||
@@ -132,6 +141,9 @@ extension OpenAISwift {
|
|||||||
let res = try JSONDecoder().decode(OpenAI<MessageResult>.self, from: success)
|
let res = try JSONDecoder().decode(OpenAI<MessageResult>.self, from: success)
|
||||||
completionHandler(.success(res))
|
completionHandler(.success(res))
|
||||||
} catch {
|
} catch {
|
||||||
|
if let resp = String(data: success, encoding: .utf8) {
|
||||||
|
print("Failed to decode response:\n", resp)
|
||||||
|
}
|
||||||
completionHandler(.failure(.decodingError(error: error)))
|
completionHandler(.failure(.decodingError(error: error)))
|
||||||
}
|
}
|
||||||
case .failure(let failure):
|
case .failure(let failure):
|
||||||
|
|||||||
Reference in New Issue
Block a user