Exception: Discordrb::Errors::CodeError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/discordrb/errors.rb

Overview

Generic class for errors denoted by API error codes

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, errors = nil) ⇒ CodeError

Create a new error with a particular message (the code should be defined by the class instance variable)

Parameters:

  • message (String)

    the message to use

  • errors (Hash) (defaults to: nil)

    API errors



36
37
38
39
40
# File 'lib/discordrb/errors.rb', line 36

def initialize(message, errors = nil)
  @message = message

  @errors = errors ? flatten_errors(errors) : []
end

Class Attribute Details

.codeInteger (readonly)

Returns The error code represented by this error class.

Returns:

  • (Integer)

    The error code represented by this error class.



30
31
32
# File 'lib/discordrb/errors.rb', line 30

def code
  @code
end

Instance Attribute Details

#errorsHash (readonly)

Returns More precise errors.

Returns:

  • (Hash)

    More precise errors



58
59
60
# File 'lib/discordrb/errors.rb', line 58

def errors
  @errors
end

#messageString (readonly)

Returns This error's represented message.

Returns:

  • (String)

    This error's represented message



55
56
57
# File 'lib/discordrb/errors.rb', line 55

def message
  @message
end

Instance Method Details

#codeInteger

Returns The error code represented by this error.

Returns:

  • (Integer)

    The error code represented by this error.



43
44
45
# File 'lib/discordrb/errors.rb', line 43

def code
  self.class.code
end

#full_messageString

Returns A message including the message and flattened errors.

Returns:

  • (String)

    A message including the message and flattened errors.



48
49
50
51
52
# File 'lib/discordrb/errors.rb', line 48

def full_message(*)
  error_list = @errors.collect { |err| "\t- #{err}" }

  "#{@message}\n#{error_list.join("\n")}"
end