From c4a3c425a8a260a89c1b2200afb5c5b6e1ec815f Mon Sep 17 00:00:00 2001 From: lxsang Date: Tue, 22 Sep 2020 16:51:01 +0200 Subject: [PATCH] enhance error handling --- talk/controllers/CommentController.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/talk/controllers/CommentController.lua b/talk/controllers/CommentController.lua index 7e09685..8383592 100644 --- a/talk/controllers/CommentController.lua +++ b/talk/controllers/CommentController.lua @@ -25,6 +25,10 @@ function CommentController:index(...) result("") return false end + if not REQUEST.json then + fail("Invalid request") + return false + end local rq = (JSON.decodeString(REQUEST.json)) if (rq) then local pages, order = self.pages:find({exp = {["="] = {uri = rq.page}}}) @@ -82,6 +86,10 @@ function CommentController:post(...) result("") return false end + if not REQUEST.json then + fail("Invalid request") + return false + end local rq = (JSON.decodeString(REQUEST.json)) if rq then local pages, order = self.pages:find({exp = {["="] = rq.page}}) @@ -136,6 +144,10 @@ function CommentController:preview(...) result("") return false end + if not REQUEST.json then + fail("Invalid request") + return false + end local rq = (JSON.decodeString(REQUEST.json)) if (rq and rq.data) then result(process_md(rq.data))