-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors_controller.rb
More file actions
34 lines (26 loc) · 984 Bytes
/
errors_controller.rb
File metadata and controls
34 lines (26 loc) · 984 Bytes
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
class ErrorsController < ApplicationController
layout 'errors'
rescue_from StandardError, with: :handle_rendering_error
def forbidden
render_error_page('errors/forbidden', :forbidden, '403 Forbidden')
end
def not_found
render_error_page('errors/not_found', :not_found, '404 Not Found')
end
def unacceptable
render_error_page('errors/unacceptable', :not_acceptable, '406 Not Acceptable')
end
def unprocessable_content
render_error_page('errors/unprocessable_content', :unprocessable_content, '422 Unprocessable Entity')
end
def internal_server_error
render_error_page('errors/internal_server_error', :internal_server_error, '500 Internal Server Error')
end
private
def render_error_page(template, status, fallback_message)
render template: template, status: status
rescue StandardError => e
Rails.logger.error("Error rendering #{status} page: #{e.message}")
render plain: fallback_message, status: status
end
end