changeset 4247:1f93fa24611d

mod_rest: Use promise based HTTP client API Doesn't really simplify anything much.
author Kim Alvefur <zash@zash.se>
date Sun, 15 Nov 2020 15:33:56 +0100
parents 53ae1df31950
children f3fbfde9683d
files mod_rest/mod_rest.lua
diffstat 1 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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;