Class: Apia::Definitions::Error
- Inherits:
-
Apia::Definition
- Object
- Apia::Definition
- Apia::Definitions::Error
- Defined in:
- lib/apia/definitions/error.rb
Instance Attribute Summary collapse
-
#catchable_exceptions ⇒ Object
readonly
Returns the value of attribute catchable_exceptions.
-
#code ⇒ Object
Returns the value of attribute code.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
Attributes inherited from Apia::Definition
#description, #id, #name, #schema
Instance Method Summary collapse
- #dsl ⇒ Object
-
#http_status_code ⇒ Integer
Return the actual HTTP status code.
- #setup ⇒ Object
-
#validate(errors) ⇒ void
Validate that this error class is valid and thus can be used in the API.
Methods inherited from Apia::Definition
Constructor Details
This class inherits a constructor from Apia::Definition
Instance Attribute Details
#catchable_exceptions ⇒ Object (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 |
#code ⇒ Object
Returns the value of attribute code.
11 12 13 |
# File 'lib/apia/definitions/error.rb', line 11 def code @code end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
13 14 15 |
# File 'lib/apia/definitions/error.rb', line 13 def fields @fields end |
#http_status ⇒ Object
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
#dsl ⇒ Object
21 22 23 |
# File 'lib/apia/definitions/error.rb', line 21 def dsl @dsl ||= DSLs::Error.new(self) end |
#http_status_code ⇒ Integer
Return the actual HTTP status code
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 |
#setup ⇒ Object
16 17 18 19 |
# File 'lib/apia/definitions/error.rb', line 16 def setup @fields = FieldSet.new @catchable_exceptions = {} end |
#validate(errors) ⇒ void
This method returns an undefined value.
Validate that this error class is valid and thus can be used in the API.
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 |