File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 59
59
end )
60
60
consume_json_head = S (" \t\n\r " ) ^ 0 * P (" data: " ) * C (consume_json ) * C (P (1 ) ^ 0 )
61
61
end
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
+ })
62
68
local ChatSession
63
69
do
64
70
local _class_0
99
105
stream = stream_callback and true or nil
100
106
}, stream_callback )
101
107
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
103
118
end
104
119
if stream_callback then
105
120
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
78
78
S ( " \t\n\r " ) ^ 0 * P ( " data: " ) * C ( consume_json) * C ( P ( 1 ) ^ 0 )
79
79
80
80
81
+ parse_error_message = types. partial {
82
+ error : types. partial {
83
+ message : types. string\ tag " message"
84
+ code : types. string\ tag " code"
85
+ }
86
+ }
81
87
82
88
-- handles appending response for each call to chat
83
89
-- TODO: hadle appending the streaming response to the output
@@ -119,7 +125,12 @@ class ChatSession
119
125
} , stream_callback
120
126
121
127
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
123
134
124
135
-- if we are streaming we need to pase the entire fragmented response
125
136
if stream_callback
You can’t perform that action at this time.
0 commit comments