comparison mod_rest/mod_rest.lua @ 3866:c0df50ce96f0

mod_rest: Handle internal http request errors early and then return Skips over attempted parsing of the payload which usually failed since the body is an error string like "connection refused", so this produced useless errors.
author Kim Alvefur <zash@zash.se>
date Sat, 25 Jan 2020 20:22:12 +0100
parents a44e20cbd986
children 839224be5299
comparison
equal deleted inserted replaced
3865:a44e20cbd986 3866:c0df50ce96f0
222 Accept = table.concat(supported_types, ", "); 222 Accept = table.concat(supported_types, ", ");
223 }, 223 },
224 }, function (body, code, response) 224 }, function (body, code, response)
225 if code == 0 then 225 if code == 0 then
226 module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body); 226 module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body);
227 origin.send(st.error_reply(stanza, "wait", "recipient-unavailable", body));
228 return;
227 else 229 else
228 module:set_status("info", "Connected"); 230 module:set_status("info", "Connected");
229 end 231 end
230 if (code == 202 or code == 204) and not reply_needed then 232 if (code == 202 or code == 204) and not reply_needed then
231 -- Delivered, no reply 233 -- Delivered, no reply
273 reply = st.error_reply(stanza, errors.new(code, nil, code2err)); 275 reply = st.error_reply(stanza, errors.new(code, nil, code2err));
274 elseif code_hundreds == 400 then 276 elseif code_hundreds == 400 then
275 reply = st.error_reply(stanza, "modify", "bad-request", body); 277 reply = st.error_reply(stanza, "modify", "bad-request", body);
276 elseif code_hundreds == 500 then 278 elseif code_hundreds == 500 then
277 reply = st.error_reply(stanza, "cancel", "internal-server-error", body); 279 reply = st.error_reply(stanza, "cancel", "internal-server-error", body);
278 elseif code == 0 then
279 reply = st.error_reply(stanza, "wait", "recipient-unavailable", body);
280 else 280 else
281 reply = st.error_reply(stanza, "cancel", "undefined-condition", body); 281 reply = st.error_reply(stanza, "cancel", "undefined-condition", body);
282 end 282 end
283 end 283 end
284 284