Exception: Apia::MissingArgumentError

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

Overview

This is raised when an argument set cannot be created because an argument that was required is not present on the source object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argument, path: []) ⇒ MissingArgumentError

Returns a new instance of MissingArgumentError.



12
13
14
15
# File 'lib/apia/errors/missing_argument_error.rb', line 12

def initialize(argument, path: [])
  @argument = argument
  @path = path
end

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



10
11
12
# File 'lib/apia/errors/missing_argument_error.rb', line 10

def argument
  @argument
end

Instance Method Details

#hashObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/apia/errors/missing_argument_error.rb', line 25

def hash
  {
    code: 'missing_required_argument',
    description: "The '#{path_string}' argument is required but has not been provided",
    detail: {
      path: @path.map(&:name),
      argument: {
        name: argument.name,
        description: argument.description
      }
    }
  }
end

#http_statusObject



17
18
19
# File 'lib/apia/errors/missing_argument_error.rb', line 17

def http_status
  400
end

#path_stringObject



21
22
23
# File 'lib/apia/errors/missing_argument_error.rb', line 21

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