changeset 3909:eb27e51cf2c9

mod_rest: Handle uncaught native errors correctly Previously they would slip through and be returned over HTTP with 200 OK.
author Matthew Wild <mwild1@gmail.com>
date Wed, 26 Feb 2020 18:04:17 +0000
parents 8ac5d9933106
children 49efd1323a1b
files mod_rest/mod_rest.lua
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Wed Feb 26 17:57:53 2020 +0000
+++ b/mod_rest/mod_rest.lua	Wed Feb 26 18:04:17 2020 +0000
@@ -142,7 +142,10 @@
 				return encode(send_type, result.stanza);
 			end,
 			function (error)
-				if error.context and error.context.stanza then
+				if not errors.is_err(error) then
+					module:log("error", "Uncaught native error: %s", error);
+					return select(2, errors.coerce(nil, error));
+				elseif error.context and error.context.stanza then
 					response.headers.content_type = send_type;
 					module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag());
 					return encode(send_type, error.context.stanza);