Class: ErrorsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ErrorsController
- Defined in:
- app/controllers/errors_controller.rb
Overview
Controller for handling application errors with custom pages Provides consistent error pages for both UI and API requests nosemgrep: ruby.lang.security.missing-csrf-protection.missing-csrf-protection
Instance Method Summary collapse
-
#bad_request ⇒ Object
400 Bad Request.
-
#forbidden ⇒ Object
403 Forbidden.
-
#internal_server_error ⇒ Object
500 Internal Server Error.
-
#not_acceptable ⇒ Object
406 Not Acceptable.
-
#not_found ⇒ Object
404 Not Found.
-
#service_unavailable ⇒ Object
503 Service Unavailable.
-
#unauthorized ⇒ Object
401 Unauthorized.
-
#unprocessable_entity ⇒ Object
422 Unprocessable Entity.
Instance Method Details
#bad_request ⇒ Object
400 Bad Request
17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/errors_controller.rb', line 17 def bad_request @error_code = 400 @error_title = "Bad Request" @error_message = params[:message] || "The request could not be understood by the server." @error_details = params[:details] @status = :bad_request respond_to_error end |
#forbidden ⇒ Object
403 Forbidden
39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/errors_controller.rb', line 39 def forbidden @error_code = 403 @error_title = "Forbidden" @error_message = params[:message] || "You don't have permission to access this resource." @error_details = params[:details] @status = :forbidden respond_to_error end |
#internal_server_error ⇒ Object
500 Internal Server Error
83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/errors_controller.rb', line 83 def internal_server_error @error_code = 500 @error_title = "Internal Server Error" @error_message = params[:message] || "Something went wrong on our end. We're working to fix it." @error_details = params[:details] @status = :internal_server_error respond_to_error end |
#not_acceptable ⇒ Object
406 Not Acceptable
61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/errors_controller.rb', line 61 def not_acceptable @error_code = 406 @error_title = "Not Acceptable" @error_message = params[:message] || "The requested resource cannot be provided in a format your browser accepts. Please try using a different browser or update your current browser." @error_details = params[:details] @status = :not_acceptable respond_to_error end |
#not_found ⇒ Object
404 Not Found
50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/errors_controller.rb', line 50 def not_found @error_code = 404 @error_title = "Page Not Found" @error_message = params[:message] || "The page you're looking for doesn't exist." @error_details = params[:details] @status = :not_found respond_to_error end |
#service_unavailable ⇒ Object
503 Service Unavailable
94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/errors_controller.rb', line 94 def service_unavailable @error_code = 503 @error_title = "Service Unavailable" @error_message = params[:message] || "The service is temporarily unavailable. Please try again later." @error_details = params[:details] @status = :service_unavailable respond_to_error end |
#unauthorized ⇒ Object
401 Unauthorized
28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/errors_controller.rb', line 28 def @error_code = 401 @error_title = "Unauthorized" @error_message = params[:message] || "You need to sign in or sign up before continuing." @error_details = params[:details] @status = :unauthorized respond_to_error end |
#unprocessable_entity ⇒ Object
422 Unprocessable Entity
72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/errors_controller.rb', line 72 def unprocessable_entity @error_code = 422 @error_title = "Unprocessable Entity" @error_message = params[:message] || "The request was well-formed but contains invalid data." @error_details = params[:details] @status = :unprocessable_entity respond_to_error end |