Class: LightServiceExt::ErrorInfo
- Inherits:
-
Object
- Object
- LightServiceExt::ErrorInfo
- Defined in:
- lib/light-service-ext/error_info.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #backtrace ⇒ Object
- #clean_backtrace ⇒ Object
- #error_summary ⇒ Object
- #errors ⇒ Object
- #fatal_error? ⇒ Boolean
-
#initialize(error, message: nil, fatal: false) ⇒ ErrorInfo
constructor
A new instance of ErrorInfo.
- #non_fatal_error? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(error, message: nil, fatal: false) ⇒ ErrorInfo
Returns a new instance of ErrorInfo.
7 8 9 10 11 12 13 |
# File 'lib/light-service-ext/error_info.rb', line 7 def initialize(error, message: nil, fatal: false) @fatal = fatal @error = error @type = error.class.name @message = || error.try(:message) @title = "#{error.class.name} : #{error&.}" end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/light-service-ext/error_info.rb', line 5 def error @error end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/light-service-ext/error_info.rb', line 5 def @message end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/light-service-ext/error_info.rb', line 5 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/light-service-ext/error_info.rb', line 5 def type @type end |
Instance Method Details
#backtrace ⇒ Object
51 52 53 |
# File 'lib/light-service-ext/error_info.rb', line 51 def backtrace error&.backtrace || [] end |
#clean_backtrace ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/light-service-ext/error_info.rb', line 55 def clean_backtrace @clean_backtrace ||= if defined? Rails.backtrace_cleaner Rails.backtrace_cleaner.clean(backtrace || []) else backtrace || [] end end |
#error_summary ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/light-service-ext/error_info.rb', line 19 def error_summary header = fatal_error? ? "SERVER ERROR FOUND" : "ERROR FOUND" <<~TEXT =========== #{header}: #{title} =========== FULL STACK TRACE #{clean_backtrace.join("\n")} #{'=' * 56} TEXT end |
#errors ⇒ Object
32 33 34 35 36 37 |
# File 'lib/light-service-ext/error_info.rb', line 32 def errors model = error.try(:model) || error.try(:record) = model.present? ? model.errors. : error. { base: } end |
#fatal_error? ⇒ Boolean
15 16 17 |
# File 'lib/light-service-ext/error_info.rb', line 15 def fatal_error? @fatal || !non_fatal_error? end |
#non_fatal_error? ⇒ Boolean
63 64 65 |
# File 'lib/light-service-ext/error_info.rb', line 63 def non_fatal_error? error.nil? || LightServiceExt.config.non_fatal_error?(error) end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/light-service-ext/error_info.rb', line 39 def to_h { type: type, message: , exception: title, backtrace: clean_backtrace[0, 5]&.join("\n"), error: error, fatal_error?: fatal_error?, errors: errors } end |