Exception: Ably::Exceptions::BaseAblyException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/submodules/ably-ruby/lib/ably/exceptions.rb

Overview

Base Ably exception class that contains status and code values used by Ably Refer to github.com/ably/ably-common/blob/main/protocol/errors.json

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status = nil, code = nil, base_exception = nil, options = {}) ⇒ BaseAblyException

Returns a new instance of BaseAblyException.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 19

def initialize(message, status = nil, code = nil, base_exception = nil, options = {})
  super message

  @base_exception = base_exception
  @status = status
  @status ||= base_exception.status if base_exception && base_exception.respond_to?(:status)
  @status ||= options[:fallback_status]
  @code = code
  @code ||= base_exception.code if base_exception && base_exception.respond_to?(:code)
  @code ||= options[:fallback_code]
  @request_id ||= options[:request_id]
end

Instance Attribute Details

#codeString (readonly)

Returns Ably specific error code.

Returns:

  • (String)

    Ably specific error code



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 16

class BaseAblyException < StandardError
  attr_reader :status, :code, :request_id

  def initialize(message, status = nil, code = nil, base_exception = nil, options = {})
    super message

    @base_exception = base_exception
    @status = status
    @status ||= base_exception.status if base_exception && base_exception.respond_to?(:status)
    @status ||= options[:fallback_status]
    @code = code
    @code ||= base_exception.code if base_exception && base_exception.respond_to?(:code)
    @code ||= options[:fallback_code]
    @request_id ||= options[:request_id]
  end

  def to_s
    message = [super]
    if status || code
      additional_info = []
      additional_info << "code: #{code}" if code
      additional_info << "http status: #{status}" if status
      additional_info << "base exception: #{@base_exception.class}" if @base_exception
      additional_info << "request_id: #{request_id}" if request_id
      message << "(#{additional_info.join(', ')})"
      message << "-> see https://help.ably.io/error/#{code} for help" if code
    end
    message.join(' ')
  end

  def as_json(*args)
    {
      message: "#{self.class}: #{message}",
      status: @status,
      code: @code
    }.delete_if { |key, val| val.nil? }
  end
end

#messageString (readonly)

Returns Error message from Ably.

Returns:

  • (String)

    Error message from Ably



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 16

class BaseAblyException < StandardError
  attr_reader :status, :code, :request_id

  def initialize(message, status = nil, code = nil, base_exception = nil, options = {})
    super message

    @base_exception = base_exception
    @status = status
    @status ||= base_exception.status if base_exception && base_exception.respond_to?(:status)
    @status ||= options[:fallback_status]
    @code = code
    @code ||= base_exception.code if base_exception && base_exception.respond_to?(:code)
    @code ||= options[:fallback_code]
    @request_id ||= options[:request_id]
  end

  def to_s
    message = [super]
    if status || code
      additional_info = []
      additional_info << "code: #{code}" if code
      additional_info << "http status: #{status}" if status
      additional_info << "base exception: #{@base_exception.class}" if @base_exception
      additional_info << "request_id: #{request_id}" if request_id
      message << "(#{additional_info.join(', ')})"
      message << "-> see https://help.ably.io/error/#{code} for help" if code
    end
    message.join(' ')
  end

  def as_json(*args)
    {
      message: "#{self.class}: #{message}",
      status: @status,
      code: @code
    }.delete_if { |key, val| val.nil? }
  end
end

#request_idObject (readonly)

Returns the value of attribute request_id.



17
18
19
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 17

def request_id
  @request_id
end

#statusString (readonly)

Returns HTTP status code of error.

Returns:

  • (String)

    HTTP status code of error



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 16

class BaseAblyException < StandardError
  attr_reader :status, :code, :request_id

  def initialize(message, status = nil, code = nil, base_exception = nil, options = {})
    super message

    @base_exception = base_exception
    @status = status
    @status ||= base_exception.status if base_exception && base_exception.respond_to?(:status)
    @status ||= options[:fallback_status]
    @code = code
    @code ||= base_exception.code if base_exception && base_exception.respond_to?(:code)
    @code ||= options[:fallback_code]
    @request_id ||= options[:request_id]
  end

  def to_s
    message = [super]
    if status || code
      additional_info = []
      additional_info << "code: #{code}" if code
      additional_info << "http status: #{status}" if status
      additional_info << "base exception: #{@base_exception.class}" if @base_exception
      additional_info << "request_id: #{request_id}" if request_id
      message << "(#{additional_info.join(', ')})"
      message << "-> see https://help.ably.io/error/#{code} for help" if code
    end
    message.join(' ')
  end

  def as_json(*args)
    {
      message: "#{self.class}: #{message}",
      status: @status,
      code: @code
    }.delete_if { |key, val| val.nil? }
  end
end

Instance Method Details

#as_json(*args) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 46

def as_json(*args)
  {
    message: "#{self.class}: #{message}",
    status: @status,
    code: @code
  }.delete_if { |key, val| val.nil? }
end

#to_sObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/submodules/ably-ruby/lib/ably/exceptions.rb', line 32

def to_s
  message = [super]
  if status || code
    additional_info = []
    additional_info << "code: #{code}" if code
    additional_info << "http status: #{status}" if status
    additional_info << "base exception: #{@base_exception.class}" if @base_exception
    additional_info << "request_id: #{request_id}" if request_id
    message << "(#{additional_info.join(', ')})"
    message << "-> see https://help.ably.io/error/#{code} for help" if code
  end
  message.join(' ')
end