Changeset

2211:9aecf7c953ba

mod_http_roster_admin: Also log if the status error is 0 (Connection refused) (Also replaced spaced indentation with tabs, as is the convention)
author JC Brand <jcbrand@minddistrict.com>
date Tue, 14 Jun 2016 14:15:59 +0000
parents 2209:2733cb8c82a9 (current diff) 2210:126d79bf079b (diff)
children 2212:57dcad6543c9
files
diffstat 1 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_roster_admin/mod_http_roster_admin.lua	Mon Jun 13 13:15:07 2016 +0100
+++ b/mod_http_roster_admin/mod_http_roster_admin.lua	Tue Jun 14 14:15:59 2016 +0000
@@ -125,23 +125,25 @@
 -- Fetch the named user's roster from the API, call callback (cb)
 -- with status and result (friends list) when received.
 function fetch_roster(username, cb)
-    local x = {headers = {}};
-    x["headers"]["ACCEPT"] = "application/json, text/plain, */*";
+	local x = {headers = {}};
+	x["headers"]["ACCEPT"] = "application/json, text/plain, */*";
 	local ok, err = http.request(
-        roster_url:format(username),
-        x,
-        function (roster_data, code)
-            if code ~= 200 then
-                if code ~= 0 then
-                    module:log("error", "Error fetching roster from %s (code %d): %s", roster_url:format(username), code, tostring(roster_data):sub(1, 40):match("^[^\r\n]+"));
-                    cb(nil, code, roster_data);
-                end
-                return;
-            end
-        module:log("debug", "Successfully fetched roster for %s", username);
-        module:log("debug", "The roster data is %s", roster_data);
-        cb(true, code, json.decode(roster_data));
-	end);
+		roster_url:format(username),
+		x,
+		function (roster_data, code)
+			if code ~= 200 then
+				module:log("error", "Error fetching roster from %s (code %d): %s", roster_url:format(username), code, tostring(roster_data):sub(1, 40):match("^[^\r\n]+"));
+				if code ~= 0 then
+					cb(nil, code, roster_data);
+				end
+				return;
+			end
+			module:log("debug", "Successfully fetched roster for %s", username);
+			module:log("debug", "The roster data is %s", roster_data);
+			cb(true, code, json.decode(roster_data));
+		end
+	);
+	module:log("debug", "fetch_roster: ok is %s", ok);
 	if not ok then
 		module:log("error", "Failed to connect to roster API at %s: %s", roster_url:format(username), err);
 		cb(false, 0, err);