module Thoth::Helper::Error
The Error
helper module provides methods for interrupting the current request and responding with an error message and corresponding HTTP error code.
Public Instance Methods
error_400(message = nil)
click to toggle source
Displays a “400 Bad Request” error message and returns a 400 response code.
# File lib/thoth/helper/error.rb, line 39 def error_400(message = nil) if message error_layout 400, '400 Bad Request', %[ <p> Your browser sent a request that this server could not understand. </p> <p> #{message} </p> ] else error_layout 400, '400 Bad Request', %[ <p> Your browser sent a request that this server could not understand. </p> ] end end
error_403()
click to toggle source
Displays a “403 Forbidden” error message and returns a 403 response code.
# File lib/thoth/helper/error.rb, line 60 def error_403 error_layout 403, '403 Forbidden', %[ <p> You don't have permission to access <code>#{h(request.REQUEST_URI)}</code> on this server. </p> ] end
error_404()
click to toggle source
Displays a “404 Not Found” error message and returns a 404 response code.
# File lib/thoth/helper/error.rb, line 70 def error_404 error_layout 404, '404 Not Found', %[ <p> The requested URL <code>#{h(request.REQUEST_URI)}</code> was not found on this server. </p> ] end
error_405()
click to toggle source
Displays a “405 Method Not Allowed” error message and returns a 405 response code.
# File lib/thoth/helper/error.rb, line 81 def error_405 error_layout 405, '405 Method Not Allowed', %[ <p> The #{request.env['REQUEST_METHOD']} method is not allowed for the requested URL. </p> ] end
error_500()
click to toggle source
Displays a “500 Internal Server Error” error message and returns a 500 response code.
# File lib/thoth/helper/error.rb, line 92 def error_500 if e = request.env[Rack::RouteExceptions::EXCEPTION] Ramaze::Log.error e end error_layout 500, '500 Internal Server Error', %[ <p> The server encountered an internal error and was unable to complete your request. </p> ] end
Private Instance Methods
error_layout(status, title, content = '')
click to toggle source
# File lib/thoth/helper/error.rb, line 107 def error_layout(status, title, content = '') respond! %[ <html> <head> <title>#{h(title)}</title> </head> <body> <h1>#{h(title)}</h1> #{content} </body> </html> ].unindent, status end