Software /
code /
prosody-modules
Diff
mod_rest/mod_rest.lua @ 3862:3b6b8dcff78e
mod_rest: Log connectivity problems via module status API
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 25 Jan 2020 20:06:48 +0100 |
parent | 3861:ede3d1724dd1 |
child | 3864:d845475c75f3 |
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua Sat Jan 25 20:04:39 2020 +0100 +++ b/mod_rest/mod_rest.lua Sat Jan 25 20:06:48 2020 +0100 @@ -153,9 +153,15 @@ send_type = "application/json"; end + module:set_status("info", "Not yet connected"); http.request(rest_url, { method = "OPTIONS", }, function (body, code, response) + if code == 0 then + return module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body); + else + module:set_status("info", "Connected"); + end if code == 200 and response.headers.accept then send_type = decide_type(response.headers.accept); module:log("debug", "Set 'rest_callback_content_type' = %q based on Accept header", send_type); @@ -216,6 +222,11 @@ Accept = table.concat(supported_types, ", "); }, }, function (body, code, response) + if code == 0 then + return module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body); + else + module:set_status("info", "Connected"); + end if (code == 202 or code == 204) and not reply_needed then -- Delivered, no reply return;