Class: Kogno::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/core/lib/error_handler.rb

Class Method Summary collapse

Class Method Details

.notify_by_slack(username, error, token) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/core/lib/error_handler.rb', line 9

def notify_by_slack(username, error, token)
  
  error_message = %{```
Error Message: #{error.message[0..256]}
Error Token: #{token}
Backtrace:#{error.backtrace.join("\n\t")[0..1024]}
```}
  
  url = URI(Kogno::Application.config.error_notifier.slack[:webhook])
  
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  
  request = Net::HTTP::Post.new(url)
  request["content-type"] = 'application/json'
  request.body = {
    username: username,
    text: error_message
  }.to_json
  
  response = http.request(request)
  logger.write "-- This error was notified in Slack ---", :red
end