Changeset

3872:513a8a7fab41

mod_rest: Hide JSON error behind a flag It's a bit overzealous and returns JSON errors even if you ask for HTML.
author Kim Alvefur <zash@zash.se>
date Mon, 03 Feb 2020 23:09:38 +0100
parents 3871:e5d08bb58155
children 3873:fea0c1bed1a0
files mod_rest/mod_rest.lua
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Sat Feb 01 00:38:10 2020 +0100
+++ b/mod_rest/mod_rest.lua	Mon Feb 03 23:09:38 2020 +0100
@@ -315,17 +315,19 @@
 	end
 end
 
-local http_server = require "net.http.server";
-module:hook_object_event(http_server, "http-error", function (event)
-	local request, response = event.request, event.response;
-	if true or decide_type(request and request.headers.accept or "") == "application/json" then
-		if response then
-			response.headers.content_type = "application/json";
+if module:get_option_boolean("rest_json_errors", false) then
+	local http_server = require "net.http.server";
+	module:hook_object_event(http_server, "http-error", function (event)
+		local request, response = event.request, event.response;
+		if true or decide_type(request and request.headers.accept or "") == "application/json" then
+			if response then
+				response.headers.content_type = "application/json";
+			end
+			return json.encode({
+					type = "error",
+					error = event.error,
+					code = event.code,
+				});
 		end
-		return json.encode({
-				type = "error",
-				error = event.error,
-				code = event.code,
-			});
-	end
-end, 10);
+	end, 10);
+end