Improve `curl` error handling
In 40634fa, a change was introduced which caused any curl with a non-zero status code to call error with more information. I have found the forced error call to be problematic in my project. The tldr; is we are periodically calling curl to fetch data. This works fine, but when I close my laptop and come back an hour later, vim is littered with error messages due to curl attempts while there was no active network connection. I would prefer to handle these in a callback.
Normally a pcall is the best way to resolve this, but this isn't working; I suspect because it is an async call.
local result = pcall(function()
curl.get { .... }
end)
if not result then
-- Handle result
end
I think some better solutions are:
- Don't call
error. I don't think this commit actually solves the problem cited because the response is still attempted to be parsed aftererroris called. - Fire the
callbackmethod with/return some error structure. - Have
errorbe some toggled setting. e.g.curl.get { ..., display_error = false }
Please let me know what you think and if there is something I am misunderstanding about curl. Thanks for providing this library!
Don't call error. I don't think this commit actually solves the problem cited because the response is still attempted to be parsed after error is called.
Calling error is fine because it stops execution so it doesn't parse it but maybe a way to not error out but rather silently fail is fine. Also 2. would also be a fine solution. PR welcome
Is this still relevant?