Exception: Apia::InvalidArgumentError

Inherits:
RuntimeError show all
Defined in:
lib/apia/errors/invalid_argument_error.rb

Overview

Raised when an argument set cannot be created based on the source object that has been provided. For example, if a validation rule exists or a scalar cannot be parsed for the underlying object.

This is not raised for MISSING argument errors.

Constant Summary collapse

ISSUE_DESCRIPTIONS =
{
  invalid_scalar: 'The value provided was not of an appropriate type for the scalar that was requested. For example, you may have passed a string where an integer was required etc...',
  parse_error: 'The value provided could not be parsed into an appropriate value by the server. For example, if a date was expected and the value could not be interpretted as such.',
  validation_error: 'A validation rule that has been specified for this argument was not satisfied. See the further details in the response and in the documentation.',
  invalid_enum_value: 'The value provided was not one of the options suitable for the enum.',
  missing_lookup_value: 'A value for a lookup argument set has not been provided but at least one value is required.',
  ambiguous_lookup_values: 'More than one value has been provided for a lookup argument set. Only one option may be provided.'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argument, issue: nil, index: nil, path: [], errors: []) ⇒ InvalidArgumentError

Returns a new instance of InvalidArgumentError.



28
29
30
31
32
33
34
# File 'lib/apia/errors/invalid_argument_error.rb', line 28

def initialize(argument, issue: nil, index: nil, path: [], errors: [])
  @argument = argument
  @index = index
  @path = path
  @issue = issue
  @errors = errors
end

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



22
23
24
# File 'lib/apia/errors/invalid_argument_error.rb', line 22

def argument
  @argument
end

#errorsObject (readonly)

Returns the value of attribute errors.



25
26
27
# File 'lib/apia/errors/invalid_argument_error.rb', line 25

def errors
  @errors
end

#indexObject (readonly)

Returns the value of attribute index.



23
24
25
# File 'lib/apia/errors/invalid_argument_error.rb', line 23

def index
  @index
end

#issueObject (readonly)

Returns the value of attribute issue.



26
27
28
# File 'lib/apia/errors/invalid_argument_error.rb', line 26

def issue
  @issue
end

#pathObject (readonly)

Returns the value of attribute path.



24
25
26
# File 'lib/apia/errors/invalid_argument_error.rb', line 24

def path
  @path
end

Instance Method Details

#hashObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/apia/errors/invalid_argument_error.rb', line 48

def hash
  {
    code: 'invalid_argument',
    description: "The '#{path_string}' argument is invalid",
    detail: {
      path: @path.map(&:name),
      index: @index,
      issue: @issue&.to_s,
      issue_description: ISSUE_DESCRIPTIONS[@issue.to_sym],
      errors: @errors,
      argument: {
        id: argument.id,
        name: argument.name,
        description: argument.description
      }
    }
  }
end

#http_statusObject



40
41
42
# File 'lib/apia/errors/invalid_argument_error.rb', line 40

def http_status
  400
end

#path_stringObject



44
45
46
# File 'lib/apia/errors/invalid_argument_error.rb', line 44

def path_string
  @path.map(&:name).join('.')
end

#to_sObject



36
37
38
# File 'lib/apia/errors/invalid_argument_error.rb', line 36

def to_s
  @issue.to_s
end