Class: Spotify::Models::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/spotify/models/error.rb

Constant Summary collapse

DEFAULT =

Identifies that the error is returned from some request.

:default
ERRORS =

Defines the text and status for each message known.

{
  timeout: {
    status:  700,
    message: "Timed out."
  },
  unexpected_error: {
    status: 710,
    message: "Unexpected error."
  },
  max_retries: {
    status: 720,
    message: "Max retries exceeded."
  },
  not_available: {
    status: 730,
    message: "This feature is not available yet."
  },
  parser_error: {
    status: 740,
    message: "Something went wrong. Please verify the parameters"
  }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, args = {}) ⇒ Parsers::Error

Creates the message.

Parameters:

  • type (Hash)

    the type of the message to be shown.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/spotify/models/error.rb', line 47

def initialize(type, args = {})
  if type == DEFAULT
    error = {
      status:  args[:status],
      message: args[:message]
    }
  else
    error = ERRORS[type]
  end

  @status  = error[:status]
  @message = error[:message]
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/spotify/models/error.rb', line 7

def message
  @message
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/spotify/models/error.rb', line 7

def status
  @status
end

Class Method Details

.default(args = {}) ⇒ Parsers::Error

Creates an error representing the site response error.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



112
113
114
115
116
# File 'lib/spotify/models/error.rb', line 112

def self.default(args = {})
  args = Hash(args).with_indifferent_access

  self.new(:default, args)
end

.max_retriesParsers::Error

Creates an error representing that the retries limit was reached.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



84
85
86
# File 'lib/spotify/models/error.rb', line 84

def self.max_retries
  self.new(:max_retries)
end

.not_availableParsers::Error

Creates an error representing that the requested feature is not available yet.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



94
95
96
# File 'lib/spotify/models/error.rb', line 94

def self.not_available
  self.new(:not_available)
end

.parser_errorParsers::Error

Creates an error representing a parser error.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



103
104
105
# File 'lib/spotify/models/error.rb', line 103

def self.parser_error
  self.new(:parser_error)
end

.timeoutParsers::Error

Creates an error representing a timeout error.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



66
67
68
# File 'lib/spotify/models/error.rb', line 66

def self.timeout
  self.new(:timeout)
end

.unexpected_errorParsers::Error

Creates an error representing an unexpected error.

Returns:

  • (Parsers::Error)

    a message to be shown to the user.



75
76
77
# File 'lib/spotify/models/error.rb', line 75

def self.unexpected_error
  self.new(:unexpected_error)
end