Exception: TinyAppstoreConnect::ConnectAPIError

Inherits:
Error
  • Object
show all
Defined in:
lib/tiny_appstore_connect.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, status_code, errors) ⇒ ConnectAPIError

Returns a new instance of ConnectAPIError.



56
57
58
59
# File 'lib/tiny_appstore_connect.rb', line 56

def initialize(message, status_code, errors)
  @status_code, @errors = status_code, errors
  super(message)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/tiny_appstore_connect.rb', line 13

def errors
  @errors
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



13
14
15
# File 'lib/tiny_appstore_connect.rb', line 13

def status_code
  @status_code
end

Class Method Details

.from_errors(response) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tiny_appstore_connect.rb', line 20

def from_errors(response)
  status_code = response.status
  # 403 will returns content-type with value '*/*' FUCK!
  body = response.body.is_a?(String) ? JSON.load(response.body) : response.body
  errors = body['errors']
  messages = ["Check errors(#{errors.size}) from response:"]
  errors.each_with_index do |error, i|
    message = []
    message << "#{i + 1}." << "[#{error['status']}:#{error['code']}]" << "#{error['title']}:" << error['detail']
    message << "in #{error['source']}" unless error['source'].to_s.empty?

    messages << message.join(' ')
  end

  new(messages.join(' '), status_code, errors)
end

.parse(response) ⇒ Object



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

def parse(response)
  handel_error(response)
end