Mercurial > prosody-modules
comparison mod_http_roster_admin/mod_http_roster_admin.lua @ 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 | 95a9f2d234da |
children | 68ebc52222dc |
comparison
equal
deleted
inserted
replaced
2161:95a9f2d234da | 2210:126d79bf079b |
---|---|
123 end | 123 end |
124 | 124 |
125 -- Fetch the named user's roster from the API, call callback (cb) | 125 -- Fetch the named user's roster from the API, call callback (cb) |
126 -- with status and result (friends list) when received. | 126 -- with status and result (friends list) when received. |
127 function fetch_roster(username, cb) | 127 function fetch_roster(username, cb) |
128 local x = {headers = {}}; | 128 local x = {headers = {}}; |
129 x["headers"]["ACCEPT"] = "application/json, text/plain, */*"; | 129 x["headers"]["ACCEPT"] = "application/json, text/plain, */*"; |
130 local ok, err = http.request( | 130 local ok, err = http.request( |
131 roster_url:format(username), | 131 roster_url:format(username), |
132 x, | 132 x, |
133 function (roster_data, code) | 133 function (roster_data, code) |
134 if code ~= 200 then | 134 if code ~= 200 then |
135 if code ~= 0 then | 135 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]+")); |
136 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]+")); | 136 if code ~= 0 then |
137 cb(nil, code, roster_data); | 137 cb(nil, code, roster_data); |
138 end | 138 end |
139 return; | 139 return; |
140 end | 140 end |
141 module:log("debug", "Successfully fetched roster for %s", username); | 141 module:log("debug", "Successfully fetched roster for %s", username); |
142 module:log("debug", "The roster data is %s", roster_data); | 142 module:log("debug", "The roster data is %s", roster_data); |
143 cb(true, code, json.decode(roster_data)); | 143 cb(true, code, json.decode(roster_data)); |
144 end); | 144 end |
145 ); | |
146 module:log("debug", "fetch_roster: ok is %s", ok); | |
145 if not ok then | 147 if not ok then |
146 module:log("error", "Failed to connect to roster API at %s: %s", roster_url:format(username), err); | 148 module:log("error", "Failed to connect to roster API at %s: %s", roster_url:format(username), err); |
147 cb(false, 0, err); | 149 cb(false, 0, err); |
148 end | 150 end |
149 end | 151 end |