Exception: Spotify::APIError Abstract

Inherits:
Error
  • Object
show all
Extended by:
FFI::DataConverter
Defined in:
lib/spotify/error.rb

Overview

This class is abstract.

Generic error class, extended by all libspotify errors.

Constant Summary collapse

@@code_to_class =
{ 0 => nil }

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = "#{Spotify::API.error_message(self)} (#{to_i})") ⇒ APIError

Returns a new instance of APIError.

Parameters:

  • message (String) (defaults to: "#{Spotify::API.error_message(self)} (#{to_i})")

    only to be supplied if overridden



49
50
51
# File 'lib/spotify/error.rb', line 49

def initialize(message = "#{Spotify::API.error_message(self)} (#{to_i})")
  super
end

Class Attribute Details

.to_iInteger (readonly)

Returns error code.

Returns:

  • (Integer)

    error code



38
39
40
# File 'lib/spotify/error.rb', line 38

def to_i
  @to_i
end

Class Method Details

.from_native(error, context) ⇒ Error?

Returns an error if applicable.

Parameters:

  • error (Integer)

Returns:

  • (Error, nil)

    an error, unless error symbol was OK



18
19
20
21
22
23
# File 'lib/spotify/error.rb', line 18

def from_native(error, context)
  error_class = @@code_to_class.fetch(error) do
    raise ArgumentError, "unknown error code: #{error}"
  end
  error_class.new if error_class
end

.to_native(error, context) ⇒ Symbol

From an error, retrieve it’s native value.

Parameters:

Returns:

  • (Symbol)


29
30
31
32
33
34
35
# File 'lib/spotify/error.rb', line 29

def to_native(error, context)
  if error
    error.to_i
  else
    0
  end
end

Instance Method Details

#to_iInteger

Returns error code.

Returns:

  • (Integer)

    error code



54
55
56
# File 'lib/spotify/error.rb', line 54

def to_i
  self.class.to_i
end