fix: gracefully handle failed curl (#2356)
This commit is contained in:
@@ -477,7 +477,7 @@ function M.curl(opts)
|
||||
|
||||
local completed = false
|
||||
|
||||
local active_job
|
||||
local active_job ---@type Job|nil
|
||||
|
||||
local temp_file = fn.tempname()
|
||||
local curl_body_file = temp_file .. "-request-body.json"
|
||||
@@ -501,7 +501,7 @@ function M.curl(opts)
|
||||
|
||||
local headers_reported = false
|
||||
|
||||
active_job = curl.post(spec.url, {
|
||||
local started_job, new_active_job = pcall(curl.post, spec.url, {
|
||||
headers = spec.headers,
|
||||
proxy = spec.proxy,
|
||||
insecure = spec.insecure,
|
||||
@@ -618,6 +618,14 @@ function M.curl(opts)
|
||||
end,
|
||||
})
|
||||
|
||||
if not started_job then
|
||||
local error_msg = vim.inspect(new_active_job)
|
||||
Utils.error("Failed to make LLM request: " .. error_msg)
|
||||
handler_opts.on_stop({ reason = "error", error = error_msg })
|
||||
return
|
||||
end
|
||||
active_job = new_active_job
|
||||
|
||||
api.nvim_create_autocmd("User", {
|
||||
group = group,
|
||||
pattern = M.CANCEL_PATTERN,
|
||||
|
||||
Reference in New Issue
Block a user