class ProxyTester::ErrorHandler
Attributes
handlers[R]
mutex[R]
backtrace[RW]
details_i18n[R]
exception[R]
exit_code[R]
original_message[RW]
status_code[R]
summary_i18n[R]
Public Class Methods
create(options = {}, &block)
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 32 def create(options = {}, &block) handler = new(options, &block) handlers << handler handler end
find(exception)
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 39 def find(exception) handlers.find(proc { default_handler }) { |h| h.exception == exception } end
new(options = {})
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 21 def initialize(options = {}) @exception = options.fetch(:exception) @details_i18n = options.fetch(:details) @summary_i18n = options.fetch(:summary) @exit_code = options.fetch(:exit_code, 1) @status_code = options.fetch(:status_code, :internal_server_error) rescue KeyError => e raise ArgumentError, e.message end
Private Class Methods
default_handler()
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 45 def default_handler mutex.synchronize do @default_handler ||= new( exception: StandardError, details: 'errors.default.details', summary: 'errors.default.summary', exit_code: 99, ) end end
Public Instance Methods
details(format = :plain)
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 57 def details(format = :plain) case format when :plain @details when :html Rack::Utils.escape_html(@details) else @details end end
execute(data = {})
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 87 def execute(data = {}) use(data) ProxyTester.ui_logger.fatal details ProxyTester.ui_logger.debug original_message if original_message ProxyTester.ui_logger.debug "Original Backtrace follows\n" + backtrace.join("\n") if backtrace Kernel.exit exit_code end
summary(format = :plain)
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 68 def summary(format = :plain) case format when :plain @summary when :html Rack::Utils.escape_html(@summary) else @summary end end
to_hash()
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 96 def to_hash ErrorHandler.mutex.synchronize do @details ||= I18n.t(details_i18n) @summary ||= I18n.t(summary_i18n) end { error_summary: summary, error_details: details, result: :failure, } end
to_json()
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 109 def to_json JSON.dump(to_hash) end
use(data)
click to toggle source
# File lib/proxy_tester/error_handler.rb, line 79 def use(data) data = JSON.parse(data) if data.kind_of? String data = data.symbolize_keys @details ||= I18n.t(details_i18n, data) @summary ||= I18n.t(summary_i18n, data) end