Skip to content

Commit 3acba1c

Browse files
committed
Implement IntercomError #inspect and #to_hash
These come in handy when logging error detail.
1 parent 2bb3cfb commit 3acba1c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/intercom/errors.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ def initialize(message, context={})
1010
@request_id = context[:request_id]
1111
super(message)
1212
end
13+
def inspect
14+
attributes = instance_variables.map do |var|
15+
value = instance_variable_get(var).inspect
16+
"#{var}=#{value}"
17+
end
18+
"##{self.class.name}:#{message} #{attributes.join(' ')}"
19+
end
20+
def to_hash
21+
{message: message}
22+
.merge(Hash[instance_variables.map{ |var| [var[1..-1], instance_variable_get(var)] }])
23+
end
1324
end
1425

1526
# Raised when the credentials you provide don't match a valid account on Intercom.

0 commit comments

Comments
 (0)