Class: Slack::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-wrapper/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Errors

Returns a new instance of Errors.



3
4
5
# File 'lib/slack-wrapper/errors.rb', line 3

def initialize(object)
  handle(object)
end

Instance Method Details

#handle(object) ⇒ Object

Raises:

  • (RuntimeError)


6
7
8
# File 'lib/slack-wrapper/errors.rb', line 6

def handle(object)
  raise RuntimeError, message(object)
end

#message(object) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/slack-wrapper/errors.rb', line 9

def message(object)
  case object['error']
    when nil
      error = "Undefined Error"
    when "not_authed"
      object['detail'] = "Invalid Token, check configuration"
    when String
      error = object['error']
  end
  case object['detail']
    when nil
      detail = "Details unknown"
    when String
      detail = object['detail']
  end
  "Error '#{error}' occured. Details: #{detail}"
end