Class: Megatron::ErrorsController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Gaffe::Errors
Defined in:
app/controllers/megatron/errors_controller.rb

Constant Summary collapse

JSON_RESPONSES =
{
  internal_server_error: "an unexpected error occurred",
  bad_request:           "bad request",
  forbidden:             "forbidden",
  method_not_allowed:    "method not supported",
  not_acceptable:        "not acceptable",
  not_found:             "not found",
  not_implemented:       "not implemented",
  unauthorized:          "unauthorized",
  unprocessable_entity:  "we couldn't process your input"
}.freeze

Instance Method Summary collapse

Instance Method Details

#showObject

Render the correct template based on the exception “standard” code. Eg. For a 404 error, the ‘errors/not_found` template will be rendered.



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/megatron/errors_controller.rb', line 26

def show
  respond_to do |format|
    format.html {
      # Here, the `@exception` variable contains the original raised error
      render "megatron/errors/#{@rescue_response}", status: @status_code
    }
    format.json {
      render json: { errors: JSON_RESPONSES[@rescue_response] }, status: @status_code
    }
  end
end