comparison mod_rest/mod_rest.lua @ 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 3d0e8e32453c
children 49efd1323a1b
comparison
equal deleted inserted replaced
3908:8ac5d9933106 3909:eb27e51cf2c9
140 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag()); 140 module:log("debug", "Sending[rest]: %s", result.stanza:top_tag());
141 response.headers.content_type = send_type; 141 response.headers.content_type = send_type;
142 return encode(send_type, result.stanza); 142 return encode(send_type, result.stanza);
143 end, 143 end,
144 function (error) 144 function (error)
145 if error.context and error.context.stanza then 145 if not errors.is_err(error) then
146 module:log("error", "Uncaught native error: %s", error);
147 return select(2, errors.coerce(nil, error));
148 elseif error.context and error.context.stanza then
146 response.headers.content_type = send_type; 149 response.headers.content_type = send_type;
147 module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag()); 150 module:log("debug", "Sending[rest]: %s", error.context.stanza:top_tag());
148 return encode(send_type, error.context.stanza); 151 return encode(send_type, error.context.stanza);
149 else 152 else
150 return error; 153 return error;