Skip to content

Commit e96abc9

Browse files
committed
Fix issue where chatsStream() throws incorrect error
1 parent d7f478e commit e96abc9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Sources/OpenAI/Private/StreamingSession.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,23 @@ final class StreamingSession<ResultType: Codable>: NSObject, Identifiable, URLSe
6262
onProcessingError?(self, StreamingError.unknownContent)
6363
return
6464
}
65+
66+
var apiError: Error? = nil
6567
do {
6668
let decoder = JSONDecoder()
6769
let object = try decoder.decode(ResultType.self, from: jsonData)
6870
onReceiveContent?(self, object)
6971
} catch {
70-
onProcessingError?(self, error)
72+
apiError = error
73+
}
74+
75+
if let apiError = apiError {
76+
do {
77+
let decoded = try JSONDecoder().decode(APIErrorResponse.self, from: data)
78+
onProcessingError?(self, decoded)
79+
} catch {
80+
onProcessingError?(self, apiError)
81+
}
7182
}
7283
}
7384
}

0 commit comments

Comments
 (0)