fix: handle bedrock exceptions (#1483)
This commit is contained in:
@@ -357,7 +357,7 @@ function M._stream(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- If stream is not enabled, then handle the response here
|
-- If stream is not enabled, then handle the response here
|
||||||
if spec.body.stream == false and result.status == 200 then
|
if (spec.body.stream == nil or spec.body.stream == false) and result.status == 200 then
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
completed = true
|
completed = true
|
||||||
parse_response_without_stream(result.body)
|
parse_response_without_stream(result.body)
|
||||||
|
|||||||
@@ -41,6 +41,16 @@ function M.parse_stream_data(ctx, data, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.parse_response_without_stream(data, event_state, opts)
|
||||||
|
local bedrock_match = data:gmatch("exception(%b{})")
|
||||||
|
opts.on_chunk("\n**Exception caught**\n\n")
|
||||||
|
for bedrock_data_match in bedrock_match do
|
||||||
|
local jsn = vim.json.decode(bedrock_data_match)
|
||||||
|
opts.on_chunk("- " .. jsn.message .. "\n")
|
||||||
|
end
|
||||||
|
vim.schedule(function() opts.on_stop({ reason = "complete" }) end)
|
||||||
|
end
|
||||||
|
|
||||||
---@param provider AvanteBedrockProviderFunctor
|
---@param provider AvanteBedrockProviderFunctor
|
||||||
---@param prompt_opts AvantePromptOptions
|
---@param prompt_opts AvantePromptOptions
|
||||||
---@return table
|
---@return table
|
||||||
|
|||||||
Reference in New Issue
Block a user