Skip to content

Commit

Permalink
Fix issue where chatsStream() throws incorrect error
Browse files Browse the repository at this point in the history
  • Loading branch information
longseespace committed Jul 6, 2023
1 parent d7f478e commit e96abc9
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 e96abc9

Please sign in to comment.