lua-resty-http icon indicating copy to clipboard operation
lua-resty-http copied to clipboard

Under what circumstances will request_uri() return an "error" string?

Open xt1234567 opened this issue 1 year ago • 3 comments

i use the function _M.request_uri(self, uri, params) in http.lua file, the error message it returns is the "error" string. I would like to ask whether this is a problem on the requesting side or a problem returned by the responding side. If in request side, What is the possible root cause?

xt1234567 avatar Dec 04 '23 06:12 xt1234567

It can be either. A badly formed request may return nil, err -- for example if the URI cannot be parsed correctly -- before attempting to make a connection. But also an upstream connection error, or a send / read timeout can return nil, err.

The contents of the error string should make this obvious, but please post an example if it is not.

pintsized avatar Dec 04 '23 11:12 pintsized

thank you for your reply! In my scenario, local resp, err = request_uri(url, req_params) if not resp, i will retry it and print the err content. First,the content of err is just a string "error", this is where I'm confused. Second, I retried the request and it succeeded, so it don't like the uri can't be parsed.

xt1234567 avatar Dec 05 '23 01:12 xt1234567

That is odd, but I am quite certain the error string "error" could not be generated here. Note that in many cases we simply pass on the error message from the underlying cosocket.

You could try calling httpc.debug(true) globally. This will print noisy details about the generated request to your log, and so you can compare what this library is trying to do with something like curl, for example.

Please post a minimal yet complete working example that reproduces the issue if you need more help. I am guessing otherwise.

pintsized avatar Dec 05 '23 18:12 pintsized