Class: Apia::Definitions::Error

Inherits:
Apia::Definition show all
Defined in:
lib/apia/definitions/error.rb

Instance Attribute Summary collapse

Attributes inherited from Apia::Definition

#description, #id, #name, #schema

Instance Method Summary collapse

Methods inherited from Apia::Definition

#initialize, #schema?

Constructor Details

This class inherits a constructor from Apia::Definition

Instance Attribute Details

#catchable_exceptionsObject (readonly)

Returns the value of attribute catchable_exceptions.



14
15
16
# File 'lib/apia/definitions/error.rb', line 14

def catchable_exceptions
  @catchable_exceptions
end

#codeObject

Returns the value of attribute code.



11
12
13
# File 'lib/apia/definitions/error.rb', line 11

def code
  @code
end

#fieldsObject (readonly)

Returns the value of attribute fields.



13
14
15
# File 'lib/apia/definitions/error.rb', line 13

def fields
  @fields
end

#http_statusObject

Returns the value of attribute http_status.



12
13
14
# File 'lib/apia/definitions/error.rb', line 12

def http_status
  @http_status
end

Instance Method Details

#dslObject



21
22
23
# File 'lib/apia/definitions/error.rb', line 21

def dsl
  @dsl ||= DSLs::Error.new(self)
end

#http_status_codeInteger

Return the actual HTTP status code

Returns:

  • (Integer)


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

def http_status_code
  if @http_status.is_a?(Symbol)
    ::Rack::Utils::SYMBOL_TO_STATUS_CODE[@http_status]
  else
    @http_status
  end
end

#setupObject



16
17
18
19
# File 'lib/apia/definitions/error.rb', line 16

def setup
  @fields = FieldSet.new
  @catchable_exceptions = {}
end

#validate(errors) ⇒ Object

Validate that this error class is valid and thus can be used in the API.

Parameters:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/apia/definitions/error.rb', line 41

def validate(errors)
  unless code.is_a?(Symbol)
    errors.add self, 'InvalidCode', 'Code must be a symbol'
  end

  if http_status_code.is_a?(Integer) && ::Rack::Utils::HTTP_STATUS_CODES[http_status_code]
    # OK
  elsif http_status_code.is_a?(Integer)
    errors.add self, 'InvalidHTTPStatus', "The HTTP status is not valid (must be one of #{::Rack::Utils::HTTP_STATUS_CODES.keys.join(', ')})"
  else
    errors.add self, 'InvalidHTTPStatus', 'The HTTP status is not valid (must be an integer)'
  end

  @fields.validate(errors, self)
end