Repository navigation
Expand file tree
/
Copy patherrors.lua
More file actions
96 lines (89 loc) · 2.54 KB
/
Copy patherrors.lua
File metadata and controls
96 lines (89 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
local class = require "middleclass"
local plugin = require "bunkerweb.plugin"
local ngx = ngx
local subsystem = ngx.config.subsystem
local tostring = tostring
local template
local render = nil
if subsystem == "http" then
template = require "resty.template"
render = template.render
end
local errors = class("errors", plugin)
function errors:initialize(ctx)
-- Call parent initialize
plugin.initialize(self, "errors", ctx)
-- Default error texts
self.default_errors = {
["301"] = {
title = "Moved Permanently",
text = "The requested page has moved to a new url.",
},
["302"] = {
title = "Found",
text = "The requested page has moved temporarily to a new url.",
},
["400"] = {
title = "Bad Request",
text = "The server did not understand the request.",
},
["401"] = {
title = "Not Authorized",
text = "Valid authentication credentials needed for the target resource.",
},
["403"] = {
title = "Forbidden",
text = "Access is forbidden to the requested page.",
},
["404"] = {
title = "Not Found",
text = "The server cannot find the requested page.",
},
["405"] = {
title = "Method Not Allowed",
text = "The method specified in the request is not allowed.",
},
["413"] = {
title = "Request Entity Too Large",
text = "The server will not accept the request, because the request entity is too large.",
},
["429"] = {
title = "Too Many Requests",
text = "Too many requests sent in a given amount of time, try again later.",
},
["500"] = {
title = "Internal Server Error",
text = "The request was not completed. The server met an unexpected condition.",
},
["501"] = {
title = "Not Implemented",
text = "The request was not completed. The server did not support the functionality required.",
},
["502"] = {
title = "Bad Gateway",
text = "The request was not completed. The server received an invalid response from the upstream server.",
},
["503"] = {
title = "Service Unavailable",
text = "The request was not completed. The server is temporarily overloading or down.",
},
["504"] = {
title = "Gateway Timeout",
text = "The gateway has timed out.",
},
}
end
function errors:log()
self:set_metric("counters", tostring(ngx.status), 1)
return self:ret(true, "success")
end
function errors:render_template(code)
-- Render template
render("error.html", {
title = code .. " - " .. self.default_errors[code].title,
error_title = self.default_errors[code].title,
error_code = code,
error_text = self.default_errors[code].text,
})
end
return errors