Skip to content

Commit 00e4bd4

Browse files
fix: issue where json.parse errors when receiving HTTP 204 with nobody
1 parent c0d51cd commit 00e4bd4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/openai/internal/util.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,8 @@ def force_charset!(content_type, text:)
657657
def decode_content(headers, stream:, suppress_error: false)
658658
case (content_type = headers["content-type"])
659659
in OpenAI::Internal::Util::JSON_CONTENT
660-
json = stream.to_a.join
660+
return nil if (json = stream.to_a.join).empty?
661+
661662
begin
662663
JSON.parse(json, symbolize_names: true)
663664
rescue JSON::ParserError => e
@@ -667,7 +668,11 @@ def decode_content(headers, stream:, suppress_error: false)
667668
in OpenAI::Internal::Util::JSONL_CONTENT
668669
lines = decode_lines(stream)
669670
chain_fused(lines) do |y|
670-
lines.each { y << JSON.parse(_1, symbolize_names: true) }
671+
lines.each do
672+
next if _1.empty?
673+
674+
y << JSON.parse(_1, symbolize_names: true)
675+
end
671676
end
672677
in %r{^text/event-stream}
673678
lines = decode_lines(stream)

0 commit comments

Comments
 (0)