Skip to content

Commit

Permalink
Remove underlyingError from GenerateContentError.invalidAPIKey (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Jan 25, 2024
1 parent d395e44 commit 31f762d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerateContentError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public enum GenerateContentError: Error {
case responseStoppedEarly(reason: FinishReason, response: GenerateContentResponse)

/// The provided API key is invalid.
case invalidAPIKey(underlying: Error)
case invalidAPIKey
}
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public final class GenerativeModel {
response = try await generativeAIService.loadRequest(request: generateContentRequest)
} catch {
if let error = error as? RPCError, error.isInvalidAPIKeyError() {
throw GenerateContentError.invalidAPIKey(underlying: error)
throw GenerateContentError.invalidAPIKey
}
throw GenerateContentError.internalError(underlying: error)
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/GoogleAITests/GenerativeModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,8 @@ final class GenerativeModelTests: XCTestCase {
do {
_ = try await model.generateContent(testPrompt)
XCTFail("Should throw GenerateContentError.internalError; no error thrown.")
} catch let GenerateContentError.invalidAPIKey(underlying: error as RPCError) {
XCTAssertEqual(error.status, .invalidArgument)
XCTAssertEqual(error.httpResponseCode, expectedStatusCode)
XCTAssertTrue(error.message.hasPrefix("API key not valid"))
} catch GenerateContentError.invalidAPIKey {
// Do nothing, catching a GenerateContentError.invalidAPIKey error is expected.
} catch {
XCTFail("Should throw GenerateContentError.invalidAPIKey; error thrown: \(error)")
}
Expand Down

0 comments on commit 31f762d

Please sign in to comment.