class Apia::Definitions::Error

Attributes

catchable_exceptions[R]
code[RW]
fields[R]
http_status[RW]

Public Instance Methods

dsl() click to toggle source
# File lib/apia/definitions/error.rb, line 21
def dsl
  @dsl ||= DSLs::Error.new(self)
end
http_status_code() click to toggle source

Return the actual HTTP status code

@return [Integer]

# 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
setup() click to toggle source
# File lib/apia/definitions/error.rb, line 16
def setup
  @fields = FieldSet.new
  @catchable_exceptions = {}
end
validate(errors) click to toggle source

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

@param errors [Apia::ManifestErrors] @reeturn [void]

# 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