Sha256: 52514c5f704faa72c25a1e7d9d50adae803497c30ec5632054e8e7e3802f39ba

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

module ApiControllerConcerns
  module ExceptionHandling
    extend ActiveSupport::Concern

    included do
      rescue_from Exception do |exception|
        if Rails.env.development? || Rails.env.test?
          error = { message: exception.message }

          error[:application_trace] = Rails.backtrace_cleaner.clean(exception.backtrace)
          error[:full_trace] = exception.backtrace 

          respond_to do |format|
            format.json { render json: error, status: 500 }
          end
        else
          respond_to do |format|
            format.json { render json: { error: 'Internal server error.' }, status: 500 }
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-add_ons-0.3.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.2.0 app/concerns/api_controller_concerns/exception_handling.rb