Skip to content

Commit

Permalink
Merge pull request #87 from longseespace/main
Browse files Browse the repository at this point in the history
Fix issue where chatsStream() throws incorrect error
  • Loading branch information
Krivoblotsky committed Jul 10, 2023
2 parents edfa1e6 + e96abc9 commit a51a7fd
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/OpenAI/Private/StreamingSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ final class StreamingSession<ResultType: Codable>: NSObject, Identifiable, URLSe
onProcessingError?(self, StreamingError.unknownContent)
return
}

var apiError: Error? = nil
do {
let decoder = JSONDecoder()
let object = try decoder.decode(ResultType.self, from: jsonData)
onReceiveContent?(self, object)
} catch {
onProcessingError?(self, error)
apiError = error
}

if let apiError = apiError {
do {
let decoded = try JSONDecoder().decode(APIErrorResponse.self, from: data)
onProcessingError?(self, decoded)
} catch {
onProcessingError?(self, apiError)
}
}
}
}
Expand Down

0 comments on commit a51a7fd

Please sign in to comment.