2016-01-05 15:35:07 +00:00
|
|
|
# Template for 403 Forbidden
|
2016-01-24 10:22:25 +00:00
|
|
|
def render_403(context)
|
2016-01-05 15:35:07 +00:00
|
|
|
template = <<-HTML
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
body { text-align:center;font-family:helvetica,arial;font-size:22px;
|
|
|
|
color:#888;margin:20px}
|
|
|
|
#c {margin:0 auto;width:500px;text-align:left}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>Forbidden</h2>
|
|
|
|
<h3>Kemal doesn't allow you to see this page.</h3>
|
|
|
|
<img src="/__kemal__/404.png">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
2016-01-24 10:22:25 +00:00
|
|
|
context.response.status_code = 403
|
2016-01-24 15:44:37 +00:00
|
|
|
context.response.print template
|
|
|
|
context
|
2016-01-05 15:35:07 +00:00
|
|
|
end
|
|
|
|
|
2015-12-13 08:25:04 +00:00
|
|
|
# Template for 404 Not Found
|
2016-01-24 10:22:25 +00:00
|
|
|
def render_404(context)
|
2015-12-10 18:40:39 +00:00
|
|
|
template = <<-HTML
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
body { text-align:center;font-family:helvetica,arial;font-size:22px;
|
|
|
|
color:#888;margin:20px}
|
|
|
|
#c {margin:0 auto;width:500px;text-align:left}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>Kemal doesn't know this way.</h2>
|
|
|
|
<img src="/__kemal__/404.png">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
2016-01-24 10:22:25 +00:00
|
|
|
context.response.status_code = 404
|
2016-01-24 15:44:37 +00:00
|
|
|
context.response.print template
|
|
|
|
context
|
2015-12-10 18:40:39 +00:00
|
|
|
end
|
|
|
|
|
2015-12-13 08:25:04 +00:00
|
|
|
# Template for 500 Internal Server Error
|
2016-03-08 09:03:25 +00:00
|
|
|
def render_500(context, backtrace, verbosity)
|
|
|
|
message = if verbosity
|
|
|
|
"<pre>#{backtrace}</pre>"
|
|
|
|
else
|
|
|
|
"<p>Something wrong with the server :(</p>"
|
|
|
|
end
|
|
|
|
|
2015-12-10 18:40:39 +00:00
|
|
|
template = <<-HTML
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
body { text-align:center;font-family:helvetica,arial;font-size:22px;
|
|
|
|
color:#888;margin:20px}
|
|
|
|
#c {margin:0 auto;width:500px;text-align:left}
|
2016-03-08 09:03:25 +00:00
|
|
|
pre {text-align:left;font-size:14px;color:#fff;background-color:#222;
|
|
|
|
font-family:Operator,"Source Code Pro",Menlo,Monaco,Inconsolata,monospace;
|
|
|
|
line-height:1.5;padding:10px;border-radius:2px;overflow:scroll}
|
2015-12-10 18:40:39 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>Kemal has encountered an error. (500)</h2>
|
2016-03-08 09:03:25 +00:00
|
|
|
#{message}
|
2015-12-10 18:40:39 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
2016-01-24 10:22:25 +00:00
|
|
|
context.response.status_code = 500
|
2016-01-24 15:44:37 +00:00
|
|
|
context.response.print template
|
|
|
|
context
|
2015-12-10 18:40:39 +00:00
|
|
|
end
|
2016-03-03 16:14:10 +00:00
|
|
|
|
|
|
|
# Template for 415 Unsupported media type
|
|
|
|
def render_415(context, message)
|
|
|
|
template = <<-HTML
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
body { text-align:center;font-family:helvetica,arial;font-size:22px;
|
|
|
|
color:#888;margin:20px}
|
|
|
|
#c {margin:0 auto;width:500px;text-align:left}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>Unsupported media type</h2>
|
|
|
|
<h3>#{message}</h3>
|
|
|
|
<img src="/__kemal__/404.png">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
context.response.status_code = 415
|
|
|
|
context.response.print template
|
|
|
|
context
|
|
|
|
end
|
|
|
|
|
|
|
|
# Template for 400 Bad request
|
|
|
|
def render_400(context, message)
|
|
|
|
template = <<-HTML
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
body { text-align:center;font-family:helvetica,arial;font-size:22px;
|
|
|
|
color:#888;margin:20px}
|
|
|
|
#c {margin:0 auto;width:500px;text-align:left}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h2>Bad request</h2>
|
|
|
|
<h3>#{message}</h3>
|
|
|
|
<img src="/__kemal__/404.png">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
context.response.status_code = 400
|
|
|
|
context.response.print template
|
|
|
|
context
|
|
|
|
end
|