Class: ShopifyClient::ResponseUserErrors

Inherits:
ResponseErrors show all
Defined in:
lib/shopify-client/response_user_errors.rb

Class Method Summary collapse

Methods inherited from ResponseErrors

#each, #initialize, #message?, #messages, #to_h

Constructor Details

This class inherits a constructor from ShopifyClient::ResponseErrors

Class Method Details

.find_errors(data) ⇒ Hash?

Find user errors recursively.

Parameters:

  • data (Hash)

Returns:

  • (Hash, nil)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/shopify-client/response_user_errors.rb', line 27

def find_errors(data)
  data.each do |key, value|
    return value if key == 'userErrors'

    if value.is_a?(Hash)
      errors = find_errors(value)

      return errors if errors
    end
  end

  nil
end

.from_response_data(data) ⇒ ResponseErrors

Parameters:

  • data (Hash)

    the complete response data

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/shopify-client/response_user_errors.rb', line 9

def from_response_data(data)
  errors = find_user_errors(data) || {}

  return new if errors.empty?

  new(errors.to_h do |error|
    [
      error['field'] ? error['field'].join('.') : '.',
      error['message'],
    ]
  end)
end