mod_rest: Catch and coerce errors in echo endpoint
authorKim Alvefur <zash@zash.se>
Thu, 07 Apr 2022 17:48:08 +0200
changeset 4921 9d0ec61c70a1
parent 4920 3dc8e329d233
child 4922 347e34c3c7e2
mod_rest: Catch and coerce errors in echo endpoint This should ensure problems in encode() are reported back
mod_rest/mod_rest.lua
--- a/mod_rest/mod_rest.lua	Thu Apr 07 15:39:57 2022 +0200
+++ b/mod_rest/mod_rest.lua	Thu Apr 07 17:48:08 2022 +0200
@@ -332,8 +332,10 @@
 	local send_type = decide_type((request.headers.accept or "") ..",".. (request.headers.content_type or ""), supported_outputs)
 
 	if echo then
+		local ret, err = errors.coerce(encode(send_type, payload));
+		if not ret then return err; end
 		response.headers.content_type = send_type;
-		return encode(send_type, payload);
+		return ret;
 	end
 
 	if payload.name == "iq" then