Class: Exceptify::Formatter
- Inherits:
-
Object
- Object
- Exceptify::Formatter
- Includes:
- BacktraceCleaner
- Defined in:
- lib/exceptify/modules/formatter.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
Instance Method Summary collapse
-
#backtrace_message ⇒ Object
Backtrace:
* app/controllers/my_controller.rb:99:in `specific_function' * app/controllers/my_controller.rb:70:in `specific_param' * app/controllers/my_controller.rb:53:in `my_controller_params'. -
#controller_and_action ⇒ Object
home#index.
-
#initialize(exception_or_notification, opts = {}) ⇒ Formatter
constructor
A new instance of Formatter.
-
#request_message ⇒ Object
Request:
* url : https://www.example.com/ * http_method : GET * ip_address : 127.0.0.1 * parameters : {"controller"=>"home", "action"=>"index"} * timestamp : 2019-01-01 00:00:00 UTC. -
#subtitle ⇒ Object
A NoMethodError occurred.
-
#title ⇒ Object
:warning: Error occurred in production :warning: :warning: Error occurred :warning:.
Methods included from BacktraceCleaner
Constructor Details
#initialize(exception_or_notification, opts = {}) ⇒ Formatter
Returns a new instance of Formatter.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/exceptify/modules/formatter.rb', line 13 def initialize(exception_or_notification, opts = {}) @notification = if exception_or_notification.is_a?(Notification) exception_or_notification else Notification.new(exception_or_notification, opts, backtrace_cleaner: self) end @exception = notification.exception @errors_count = notification.[:accumulated_errors_count].to_i @app_name = notification.app_name end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
11 12 13 |
# File 'lib/exceptify/modules/formatter.rb', line 11 def app_name @app_name end |
Instance Method Details
#backtrace_message ⇒ Object
Backtrace:
* app/controllers/my_controller.rb:99:in `specific_function'
* app/controllers/my_controller.rb:70:in `specific_param'
* app/controllers/my_controller.rb:53:in `my_controller_params'
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/exceptify/modules/formatter.rb', line 90 def backtrace = notification.backtrace return if backtrace.empty? text = [] text << "```" backtrace.first(3).each { |line| text << "* #{line}" } text << "```" text.join("\n") end |
#controller_and_action ⇒ Object
home#index
107 108 109 |
# File 'lib/exceptify/modules/formatter.rb', line 107 def controller_and_action notification.controller_and_action end |
#request_message ⇒ Object
Request:
* url : https://www.example.com/
* http_method : GET
* ip_address : 127.0.0.1
* parameters : {"controller"=>"home", "action"=>"index"}
* timestamp : 2019-01-01 00:00:00 UTC
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/exceptify/modules/formatter.rb', line 66 def request = notification.request_context.request return unless request [ "```", "* url : #{request.original_url}", "* http_method : #{request.method}", "* ip_address : #{request.remote_ip}", "* parameters : #{request.filtered_parameters}", "* timestamp : #{notification.}", "```" ].join("\n") end |
#subtitle ⇒ Object
A NoMethodError occurred. 3 NoMethodError occurred. A NoMethodError occurred in home#index.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/exceptify/modules/formatter.rb', line 43 def subtitle errors_text = if errors_count > 1 errors_count else /^[aeiou]/i.match?(exception.class.to_s) ? "An" : "A" end in_action = " in *#{controller_and_action}*" if controller "#{errors_text} *#{exception.class}* occurred#{in_action}." end |
#title ⇒ Object
:warning: Error occurred in production :warning: :warning: Error occurred :warning:
28 29 30 31 32 33 34 35 36 |
# File 'lib/exceptify/modules/formatter.rb', line 28 def title env = notification.env_name if env "⚠️ Error occurred in #{env} ⚠️" else "⚠️ Error occurred ⚠️" end end |