# HG changeset patch # User Kim Alvefur # Date 1605450836 -3600 # Node ID 1f93fa24611d033a7b0a341012c60f586088ec21 # Parent 53ae1df3195013f2d15a7da5455ef7ab6cb2992b mod_rest: Use promise based HTTP client API Doesn't really simplify anything much. diff -r 53ae1df31950 -r 1f93fa24611d mod_rest/mod_rest.lua --- a/mod_rest/mod_rest.lua Sun Nov 15 15:28:14 2020 +0100 +++ b/mod_rest/mod_rest.lua Sun Nov 15 15:33:56 2020 +0100 @@ -322,16 +322,11 @@ ["Content-Language"] = stanza.attr["xml:lang"], Accept = table.concat(supported_inputs, ", "); }, - }, function (body, code, response) - if code == 0 then - module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body); - origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", body)); - return; - else - module:set_status("info", "Connected"); - end + }):next(function (response) + module:set_status("info", "Connected"); local reply; + local code, body = response.code, response.body; if code == 202 or code == 204 then if not reply_needed then -- Delivered, no reply @@ -393,6 +388,10 @@ module:log("debug", "Received[rest]: %s", reply:top_tag()); origin.send(reply); + end, + function (err) + module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, err); + origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", err.text)); end); return true;