| 1 |
module Vintage |
|---|
| 2 |
# A class to render the default error pages. These will |
|---|
| 3 |
# not render if error pages are specified in the configuration. |
|---|
| 4 |
class ErrorReporter |
|---|
| 5 |
# CSS shared among error templates |
|---|
| 6 |
CSS = """ |
|---|
| 7 |
body { margin: 0px; padding: 0px; font-family: sans-serif; } |
|---|
| 8 |
h1 { background: #3E2B09; padding: 45px 10px 10px 10px; color: #6F5E3C; border: 0px; border-bottom: 2px solid #1C0907; margin: 0px; } |
|---|
| 9 |
h1 span.error { text-shadow: 0.1em 0.1em #333; color: white; } |
|---|
| 10 |
h2 { margin: 0px; padding: 5px 5px 10px 10px; font-size: 14pt !important; } |
|---|
| 11 |
h2 span.where { color: #999; } |
|---|
| 12 |
h3 { margin: 0px; padding: 10px 10px; color: #999;} |
|---|
| 13 |
ul { margin: 0px; } |
|---|
| 14 |
li { margin: 0px; padding: 0px 30px; } |
|---|
| 15 |
pre { padding: 0 30px; margin: 0px; } |
|---|
| 16 |
""" |
|---|
| 17 |
|
|---|
| 18 |
# Standard template to render for a <tt>500 Internal Server Error</tt> |
|---|
| 19 |
def self.internal_error(error, params) |
|---|
| 20 |
error_page("500 Internal Server Error", error.class.to_s, "500 Internal Server Error", error.message.to_s, "at #{error.backtrace[0]}", "<h3>Backtrace</h3>\n\t<pre>#{error.backtrace.join('\n')}</pre>", params) |
|---|
| 21 |
end |
|---|
| 22 |
|
|---|
| 23 |
# Standard template to render for a <tt>404 Page Not Found</tt> error |
|---|
| 24 |
def self.not_found(url, remote_ip, params) |
|---|
| 25 |
error_page("404 Not Found", "Page Not Found", "404 Not Found", "Request for #{url}", "from #{remote_ip}", params) |
|---|
| 26 |
end |
|---|
| 27 |
|
|---|
| 28 |
private |
|---|
| 29 |
# Standard template to render for a <tt>404 Page Not Found</tt> error |
|---|
| 30 |
def self.error_page(title, h1_primary, h1_secondary, h2_primary, h2_secondary, extra_content = "", params = {}) |
|---|
| 31 |
""" |
|---|
| 32 |
<html> |
|---|
| 33 |
<head> |
|---|
| 34 |
<title>Vintage Error: #{title}</title> |
|---|
| 35 |
<style> |
|---|
| 36 |
#{CSS} |
|---|
| 37 |
</style> |
|---|
| 38 |
</head> |
|---|
| 39 |
|
|---|
| 40 |
<body> |
|---|
| 41 |
<h1><span class='error'>#{h1_primary}</span> #{h1_secondary}</h1> |
|---|
| 42 |
<h2>#{h2_primary} <span class='where'>#{h2_secondary}</span></h2> |
|---|
| 43 |
<div> |
|---|
| 44 |
<h3>Parameters</h3> |
|---|
| 45 |
<ul> |
|---|
| 46 |
#{params == {} ? "None" : params.to_a.map{|key, val| "<li><b>" + key.to_s + "<b> = " + val.to_s + "< |
|---|
| 47 |
</ul> |
|---|
| 48 |
<br /> |
|---|
| 49 |
#{extra_content} |
|---|
| 50 |
< |
|---|
| 51 |
</body> |
|---|
| 52 |
< |
|---|
| 53 |
""" |
|---|
| 54 |
end |
|---|
| 55 |
end |
|---|
| 56 |
end |
|---|