Class: Hallon::Error

Inherits:
Spotify::Error
  • Object
show all
Defined in:
lib/hallon/error.rb

Overview

Thrown by Hallon on libspotify errors.

Hallon::Error inherits two methods from Spotify::Error:

  • Hallon::Error.explain(error) - from a Spotify error, create a descriptive string of it
  • Hallon::Error.disambiguate(error) - return the tuple of [code, symbol] of a given Spotify error

Class Method Summary collapse

Class Method Details

.maybe_raise(error, options = {}) ⇒ nil

Raise an Hallon::Error with the given errno, unless it is nil, :timeout, 0 or :ok.

Examples:


Hallon::Error.maybe_raise(error, ignore: :is_loading)

Parameters:

  • error (Fixnum, Symbol)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ignore (Array) — default: []

    other values to ignore of error

Returns:

  • (nil)

Raises:

  • (self)


30
31
32
33
34
35
36
37
38
# File 'lib/hallon/error.rb', line 30

def maybe_raise(error, options = {})
  ignore = [nil, :timeout] + Array(options[:ignore])
  return nil if ignore.include?(error)

  error, symbol = disambiguate(error)
  return symbol if symbol == :ok

  raise self, explain(error)
end

.tableHash<Symbol, Integer>

Hash of error (Symbol) to code (Integer).

Returns:

  • (Hash<Symbol, Integer>)


16
17
18
# File 'lib/hallon/error.rb', line 16

def table
  Spotify.enum_type(:error).to_hash
end