module Softwear::ErrorCatcher

Protected Instance Methods

error_report_form(error) click to toggle source
# File lib/softwear/error_catcher.rb, line 17
def error_report_form(error)
  time_of_error = Time.now.strftime("%x %I:%M %p")

  iterm_annotation("Begin #{error.class.name} (#{time_of_error})")
  Rails.logger.error "**** #{error.class.name}: #{error.message} ****\n\n"\
    "\t#{error.backtrace.join("\n\t")}"
  iterm_annotation("End #{error.class.name} (#{time_of_error})")

  @error = error
  @additional_info = gather_additional_info

  begin
    respond_to do |format|
      format.html { render 'softwear/errors/internal_server_error', layout: layout_for_error, status: 500 }
      format.js   { render 'softwear/errors/internal_server_error', layout: layout_for_error, status: 500 }
      format.json { render json: '{}', status: 500 }
    end
  rescue AbstractController::DoubleRenderError => e
    Rails.logger.error "DOUBLE RENDER ERROR IN CONTROLLER ERROR CATCHER!!! #{e.message}"
  end
end
filter_params(params) click to toggle source
# File lib/softwear/error_catcher.rb, line 39
def filter_params(params)
  new_hash = {}
  params.each do |key, value|
    new_value = value

    case value
    when Hash
      new_value = filter_params(value)
    else
      case key.to_s
      when /cc_number/ then new_value = "<FILTERED>"
      when /cc_cvc/    then new_value = "<FILTERED>"
      when /password/  then new_value = "<FILTERED>"
      end
    end

    new_hash[key] = new_value
  end
  new_hash
end
gather_additional_info() click to toggle source
# File lib/softwear/error_catcher.rb, line 60
def gather_additional_info
  JSON.pretty_generate(filter_params(params)) + "|||" +
  instance_variables
    .reject { |v| /^@_/ =~ v.to_s || %i(@view_renderer @output_buffer @view_flow @error).include?(v) }
    .map { |v| "#{v}: #{instance_variable_get(v).inspect rescue '(ERROR)'}" }
    .join("|||")
end
iterm_annotation(content) click to toggle source
# File lib/softwear/error_catcher.rb, line 13
def iterm_annotation(content)
  puts "=======================================================\033]1337;AddAnnotation=#{content}\a"
end
layout_for_error() click to toggle source
# File lib/softwear/error_catcher.rb, line 68
def layout_for_error
  user = try(:current_user) || @current_user
  user ? "application" : "no_overlay"
end