Skip to content

Commit

Permalink
Log server error responses without `-GoogleGenerativeAIDebugLogEnable…
Browse files Browse the repository at this point in the history
…d` (#177)
  • Loading branch information
andrewheard authored May 29, 2024
1 parent 97a81a2 commit 5478400
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/GoogleAI/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ struct GenerativeAIService {

// Verify the status code is 200
guard response.statusCode == 200 else {
Logging.default.error("[GoogleGenerativeAI] The server responded with an error: \(response)")
Logging.network.error("[GoogleGenerativeAI] The server responded with an error: \(response)")
if let responseString = String(data: data, encoding: .utf8) {
Logging.network.error("[GoogleGenerativeAI] Response payload: \(responseString)")
Logging.default.error("[GoogleGenerativeAI] Response payload: \(responseString)")
}

throw parseError(responseData: data)
Expand Down Expand Up @@ -89,14 +89,14 @@ struct GenerativeAIService {

// Verify the status code is 200
guard response.statusCode == 200 else {
Logging.default
Logging.network
.error("[GoogleGenerativeAI] The server responded with an error: \(response)")
var responseBody = ""
for try await line in stream.lines {
responseBody += line + "\n"
}

Logging.network.error("[GoogleGenerativeAI] Response payload: \(responseBody)")
Logging.default.error("[GoogleGenerativeAI] Response payload: \(responseBody)")
continuation.finish(throwing: parseError(responseBody: responseBody))

return
Expand Down

0 comments on commit 5478400

Please sign in to comment.