Class: Checkend::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/checkend/notice.rb

Overview

Notice represents an error payload to be sent to Checkend.

This class is typically created by NoticeBuilder from an exception, but can also be constructed manually for custom error reporting.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Notice

Returns a new instance of Notice.



29
30
31
32
33
34
35
36
# File 'lib/checkend/notice.rb', line 29

def initialize
  @backtrace = []
  @tags = []
  @context = {}
  @request = {}
  @user = {}
  @occurred_at = Time.now.utc.iso8601
end

Instance Attribute Details

#backtrace ⇒ Object

Returns the value of attribute backtrace.



16
17
18
# File 'lib/checkend/notice.rb', line 16

def backtrace
  @backtrace
end

#context ⇒ Object

Context information



21
22
23
# File 'lib/checkend/notice.rb', line 21

def context
  @context
end

#environment ⇒ Object

Metadata



26
27
28
# File 'lib/checkend/notice.rb', line 26

def environment
  @environment
end

#error_class ⇒ Object

Error information



14
15
16
# File 'lib/checkend/notice.rb', line 14

def error_class
  @error_class
end

#fingerprint ⇒ Object

Returns the value of attribute fingerprint.



17
18
19
# File 'lib/checkend/notice.rb', line 17

def fingerprint
  @fingerprint
end

#message ⇒ Object

Returns the value of attribute message.



15
16
17
# File 'lib/checkend/notice.rb', line 15

def message
  @message
end

#occurred_at ⇒ Object

Returns the value of attribute occurred_at.



27
28
29
# File 'lib/checkend/notice.rb', line 27

def occurred_at
  @occurred_at
end

#request ⇒ Object

Returns the value of attribute request.



22
23
24
# File 'lib/checkend/notice.rb', line 22

def request
  @request
end

#tags ⇒ Object

Returns the value of attribute tags.



18
19
20
# File 'lib/checkend/notice.rb', line 18

def tags
  @tags
end

#user ⇒ Object

Returns the value of attribute user.



23
24
25
# File 'lib/checkend/notice.rb', line 23

def user
  @user
end

Instance Method Details

#to_h ⇒ Hash

Convert the notice to a hash

Returns:

  • (Hash) —

    hash representation



48
49
50
51
52
53
54
55
56
# File 'lib/checkend/notice.rb', line 48

def to_h
  {
    error: error_payload,
    context: context_with_environment,
    request: request || {},
    user: user || {},
    notifier: notifier_payload
  }.compact
end

#to_json(*_args) ⇒ String

Convert the notice to a JSON string

Returns:

  • (String) —

    JSON representation



41
42
43
# File 'lib/checkend/notice.rb', line 41

def to_json(*_args)
  to_h.to_json
end