changeset 4918:9d0ec61c70a1

mod_rest: Catch and coerce errors in echo endpoint This should ensure problems in encode() are reported back
author Kim Alvefur <zash@zash.se>
date Thu, 07 Apr 2022 17:48:08 +0200
parents 3dc8e329d233
children 347e34c3c7e2
files mod_rest/mod_rest.lua
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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