-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
138 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// SwiftyGPTError.swift | ||
// | ||
// | ||
// Created by Antonio Guerra on 29/03/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct SwiftyGPTError: Error, Decodable { | ||
let message, type, code: String | ||
|
||
enum WrapperCodingKeys: CodingKey { | ||
case error | ||
} | ||
|
||
enum CodingKeys: CodingKey { | ||
case message | ||
case type | ||
case code | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let wrapper = try decoder.container(keyedBy: WrapperCodingKeys.self) | ||
let container = try wrapper.nestedContainer(keyedBy: CodingKeys.self, forKey: .error) | ||
self.message = try container.decode(String.self, forKey: .message) | ||
self.type = try container.decode(String.self, forKey: .type) | ||
self.code = try container.decode(String.self, forKey: .code) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// SwiftyGPTErrorTests.swift | ||
// | ||
// | ||
// Created by Antonio Guerra on 29/03/23. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftyGPT | ||
|
||
final class SwiftyGPTErrorTests: XCTestCase { | ||
|
||
var jsonString: String! | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
jsonString = """ | ||
{ | ||
"error": { | ||
"message": "Incorrect API key provided: sk-zVAMH****************************************o25x. You can find your API key at https://platform.openai.com/account/api-keys.", | ||
"type": "invalid_request_error", | ||
"param": null, | ||
"code": "invalid_api_key" | ||
} | ||
} | ||
""" | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
try super.tearDownWithError() | ||
jsonString = nil | ||
} | ||
|
||
func testDecode() throws { | ||
let data = jsonString.data(using: .utf8) | ||
XCTAssertNotNil(data) | ||
let error = try JSONDecoder().decode(SwiftyGPTError.self, from: data!) | ||
XCTAssertNotNil(error) | ||
} | ||
} |
Oops, something went wrong.