rails_error_notifier 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddb8fbddde2f40ab7845559326d60d30d85d871a38e3cc409da99e017bc01bbd
4
- data.tar.gz: 618456dd54b92654682356638223007c12d38fb063d50a958f23e17919333ad3
3
+ metadata.gz: 9d524a58b9bae77c3564b6013efe3e0d8f038ad44c6d9671174c1f831063d723
4
+ data.tar.gz: a8c71f89c00c5a1e9eb112c628d3045b8eb988aeabc23df5691761dcc32f8ada
5
5
  SHA512:
6
- metadata.gz: 1224236b5a0ef8cb144de875c114d90ba6aa38a2ee0056b3ca27293550df23f13f2db2b220b05b14350188673f3997ee565ddb9bcab6b92a0d8a63217d3b00da
7
- data.tar.gz: d60410172bf0b0510071b39fb588b74e7dec818091f1a83e07abe10204680d4b31a34147c4a9f0d3faca9933faeac71e8f5bafb8d64cdb66d9b5422c5c42a121
6
+ metadata.gz: d4e8f1b1ffeaed2aa3f6898c3bb33124a105056c71ddecb06f5bb3936e55e507899f9f1871f4891eac6d4d6c76c0a38433e4ca35ff257378c271d6ddb4f0bcc1
7
+ data.tar.gz: 4d364110d44b5d6d83911d997f128fcdb9f9fa01eb24a4a75d998881b4eb7ad7d97aaae2f0a29f2b92562eac2878c49656502069bbcfe0745473b0d9dc28996e
@@ -3,6 +3,7 @@ require "json"
3
3
 
4
4
  module RailsErrorNotifier
5
5
  class Notifier
6
+ MAX_FIELD_VALUE = 1024
6
7
  attr_reader :exception, :context
7
8
 
8
9
  def initialize(exception, context = {})
@@ -25,6 +26,10 @@ module RailsErrorNotifier
25
26
 
26
27
  private
27
28
 
29
+ def truncate_for_discord(text)
30
+ text[0, MAX_FIELD_VALUE - 10] # leave room for ``` block
31
+ end
32
+
28
33
  def send_to_webhook(url, payload)
29
34
  return unless url
30
35
  uri = URI(url)
@@ -32,7 +37,31 @@ module RailsErrorNotifier
32
37
  data = if url.include?("hooks.slack.com")
33
38
  { text: "#{payload[:error]}\n#{payload[:backtrace].join("\n")}" }
34
39
  else
35
- payload
40
+ backtrace_text = truncate_for_discord(payload[:backtrace].first(10).join("\n"))
41
+ context_text = truncate_for_discord(payload[:context].inspect)
42
+ data = {
43
+ name: "RailsErrorNotifier", # webhook display name
44
+ embeds: [
45
+ {
46
+ title: "🚨 Error Occurred",
47
+ description: payload[:error],
48
+ color: 0xFF0000,
49
+ fields: [
50
+ {
51
+ name: "Backtrace",
52
+ value: "```\n#{backtrace_text}\n```",
53
+ inline: false
54
+ },
55
+ {
56
+ name: "Context",
57
+ value: "```\n#{context_text}\n```",
58
+ inline: false
59
+ }
60
+ ],
61
+ timestamp: Time.now.utc.iso8601
62
+ }
63
+ ]
64
+ }
36
65
  end
37
66
 
38
67
  Net::HTTP.post(uri, data.to_json, "Content-Type" => "application/json")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsErrorNotifier
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_error_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrmalvi