From defb2c3336eca849e14f77b35e65f28006c3f4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Tue, 21 Mar 2023 11:55:29 +0100 Subject: [PATCH] Change the way the error page is rendered --- src/common/core/errors/errors.lua | 56 +++++++++---------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/common/core/errors/errors.lua b/src/common/core/errors/errors.lua index 4844480f..9d092947 100644 --- a/src/common/core/errors/errors.lua +++ b/src/common/core/errors/errors.lua @@ -1,5 +1,5 @@ -local _M = {} -_M.__index = _M +local _M = {} +_M.__index = _M local utils = require "utils" local datastore = require "datastore" @@ -15,76 +15,52 @@ function _M:init() -- Save default errors into datastore local default_errors = { ["400"] = { - title = "400 - Bad Request", body1 = "Bad Request", - body2 = "400", - body3 = "The server did not understand the request." + body2 = "The server did not understand the request." }, ["401"] = { - title = "401 - Not Authorized", body1 = "Not Authorized", - body2 = "401", - body3 = "Valid authentication credentials needed for the target resource." + body2 = "Valid authentication credentials needed for the target resource." }, ["403"] = { - title = "403 - Forbidden", body1 = "Forbidden", - body2 = "403", - body3 = "Access is forbidden to the requested page." + body2 = "Access is forbidden to the requested page." }, ["404"] = { - title = "404 - Not Found", body1 = "Not Found", - body2 = "404", - body3 = "The server cannot find the requested page." + body2 = "The server cannot find the requested page." }, ["405"] = { - title = "405 - Method Not Allowed", body1 = "Method Not Allowed", - body2 = "405", - body3 = "The method specified in the request is not allowed." + body2 = "The method specified in the request is not allowed." }, ["413"] = { - title = "413 - Request Entity Too Large", body1 = "Request Entity Too Large", - body2 = "413", - body3 = "The server will not accept the request, because the request entity is too large." + body2 = "The server will not accept the request, because the request entity is too large." }, ["429"] = { - title = "429 - Too Many Requests", body1 = "Too Many Requests", - body2 = "429", - body3 = "Too many requests sent in a given amount of time, try again later." + body2 = "Too many requests sent in a given amount of time, try again later." }, ["500"] = { - title = "500 - Internal Server Error", body1 = "Internal Server Error", - body2 = "500", - body3 = "The request was not completed. The server met an unexpected condition." + body2 = "The request was not completed. The server met an unexpected condition." }, ["501"] = { - title = "501 - Not Implemented", body1 = "Not Implemented", - body2 = "501", - body3 = "The request was not completed. The server did not support the functionality required." + body2 = "The request was not completed. The server did not support the functionality required." }, ["502"] = { - title = "502 - Bad Gateway", body1 = "Bad Gateway", - body2 = "502", - body3 = "The request was not completed. The server received an invalid response from the upstream server." + body2 = "The request was not completed. The server received an invalid response from the upstream server." }, ["503"] = { - title = "503 - Service Unavailable", body1 = "Service Unavailable", - body2 = "503", - body3 = "The request was not completed. The server is temporarily overloading or down." + body2 = "The request was not completed. The server is temporarily overloading or down." }, ["504"] = { - title = "504 - Gateway Timeout", body1 = "Gateway Timeout", - body2 = "504", - body3 = "The gateway has timed out." + body2 = "The gateway has timed out." } } local ok, err = datastore:set("plugin_errors_default_errors", cjson.encode(default_errors)) @@ -118,8 +94,8 @@ function _M.error_html(code) return false, "can't get template from datastore : " .. err end -- Compute template - return template:format(default_errors[code].title, default_errors[code].body1, default_errors[code].body2, - default_errors[code].body3), "success" + return template:format(code .. " - " .. default_errors[code].body1, code, default_errors[code].body1, + default_errors[code].body2), "success" end return _M