Sha256: e1038866be047deddfa67c3e9bb3e3c6fe253eea3e9ee5118e0e0c31db78d40f

Contents?: true

Size: 761 Bytes

Versions: 18

Compression:

Stored size: 761 Bytes

Contents

module ApiControllerConcerns
  module ExceptionHandling
    extend ActiveSupport::Concern

    included do
      rescue_from Exception do |exception|
        handle_exception(exception)
      end
    end

    private

    def handle_exception(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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rails-add_ons-2.0.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.5.2 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.5.1 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.5.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.4.1 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.4.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.3.3 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.3.2 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.3.1 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.3.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.2.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.1.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-1.0.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.6.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.5.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.4.1 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.4.0 app/concerns/api_controller_concerns/exception_handling.rb
rails-add_ons-0.3.2 app/concerns/api_controller_concerns/exception_handling.rb