Software /
code /
prosody-modules
Changeset
2210:126d79bf079b
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:13:30 +0000 |
parents | 2161:95a9f2d234da |
children | 2211:9aecf7c953ba |
files | mod_http_roster_admin/mod_http_roster_admin.lua |
diffstat | 1 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_http_roster_admin/mod_http_roster_admin.lua Fri Apr 15 16:59:27 2016 +0000 +++ b/mod_http_roster_admin/mod_http_roster_admin.lua Tue Jun 14 14:13:30 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);