Module: Thoth::Helper::Error

Defined in:
lib/thoth/helper/error.rb

Overview

The Error helper module provides methods for interrupting the current request and responding with an error message and corresponding HTTP error code.

Instance Method Summary collapse

Instance Method Details

#error_400(message = nil) ⇒ Object

Displays a “400 Bad Request” error message and returns a 400 response code.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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_403Object

Displays a “403 Forbidden” error message and returns a 403 response code.



60
61
62
63
64
65
66
67
# 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_404Object

Displays a “404 Not Found” error message and returns a 404 response code.



70
71
72
73
74
75
76
77
# 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_405Object

Displays a “405 Method Not Allowed” error message and returns a 405 response code.



81
82
83
84
85
86
87
88
# 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_500Object

Displays a “500 Internal Server Error” error message and returns a 500 response code.



92
93
94
95
96
97
98
99
100
101
102
103
# 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