Sha256: c89cf5442ce790c6b2aad3f933a20c5c21c6bce02415a917c6ab0c6dabc8bc50

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

require_dependency 'whoopsie/application_controller'

module Whoopsie
  class ErrorsController < ApplicationController
    skip_before_action :verify_authenticity_token

    class JavaScriptError < StandardError
    end

    newrelic_ignore if defined?(NewRelic) && respond_to?(:newrelic_ignore)

    # Create a JavaScript exception and notify as configured
    # Params:
    #   error_report: A hash containing :message as a string
    #   extra: Contextual data
    def create
      if Rails.application.config.whoopsie.enable
        exception = JavaScriptError.new(report_params[:message])
        report_params.merge!(extra: params[:extra]) if params[:extra]
        ExceptionNotifier.notify_exception(
          exception,
          env: request.env,
          data: report_params
        )
        render plain: 'error acknowledged', status: :ok
      else
        render plain: 'error ignored', status: :accepted
      end
    end

    # Call this method to test Whoopsie in your live production app.
    def bang
      fail('boom!')
    end

    # Make sure Whoopsie is available
    def ping
      app_name  = Rails.application.engine_name
      db_status = !ActiveRecord::Base.connection.tables.empty? ? :ok : :empty
      render plain: "#{app_name} #{db_status}"
    end

    private

    # The :extra parameter may or may not be included as part of the :error_report
    def report_params
      params.require(:error_report).permit(:message, :extra)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whoopsie-0.0.2 app/controllers/whoopsie/errors_controller.rb