File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 5959 end )
6060 consume_json_head = S (" \t\n\r " ) ^ 0 * P (" data: " ) * C (consume_json ) * C (P (1 ) ^ 0 )
6161end
62+ local parse_error_message = types .partial ({
63+ error = types .partial ({
64+ message = types .string :tag (" message" ),
65+ code = types .string :tag (" code" )
66+ })
67+ })
6268local ChatSession
6369do
6470 local _class_0
99105 stream = stream_callback and true or nil
100106 }, stream_callback )
101107 if status ~= 200 then
102- return nil , " Bad status: " .. tostring (status ), response
108+ local err_msg
109+ do
110+ local err = parse_error_message (response )
111+ if err then
112+ err_msg = " Bad status: " .. tostring (status ) .. " : " .. tostring (err .message ) .. " (" .. tostring (err .code ) .. " )"
113+ else
114+ err_msg = " Bad status: " .. tostring (status )
115+ end
116+ end
117+ return nil , err_msg , response
103118 end
104119 if stream_callback then
105120 assert (type (response ) == " string" , " Expected string response from streaming output" )
Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ consume_json_head = do
7878 S ( " \t\n\r " ) ^ 0 * P ( " data: " ) * C ( consume_json) * C ( P ( 1 ) ^ 0 )
7979
8080
81+ parse_error_message = types. partial {
82+ error : types. partial {
83+ message : types. string\ tag " message"
84+ code : types. string\ tag " code"
85+ }
86+ }
8187
8288-- handles appending response for each call to chat
8389-- TODO: hadle appending the streaming response to the output
@@ -119,7 +125,12 @@ class ChatSession
119125 } , stream_callback
120126
121127 if status != 200
122- return nil , " Bad status: #{status}" , response
128+ err_msg = if err = parse_error_message response
129+ " Bad status: #{status}: #{err.message} (#{err.code})"
130+ else
131+ " Bad status: #{status}"
132+
133+ return nil , err_msg, response
123134
124135 -- if we are streaming we need to pase the entire fragmented response
125136 if stream_callback
You can’t perform that action at this time.
0 commit comments