Class: OpenapiFirst::Failure
- Inherits:
-
Object
- Object
- OpenapiFirst::Failure
- Defined in:
- lib/openapi_first/failure.rb
Overview
A failure object returned when validation or parsing of a request or response has failed. This returned in ValidatedRequest#error and ValidatedResponse#error.
Class Method Summary collapse
Instance Method Summary collapse
- #errors([Array<OpenapiFirst: :Schema::ValidationError>, nil]) ⇒ Object
- #exception(context = nil) ⇒ Object
- #exception_message ⇒ Object
-
#message ⇒ Object
A generic error message.
-
#type([Symbol]) ⇒ Object
Example: :invalid_body.
Class Method Details
.fail!(type, message: nil, errors: nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/openapi_first/failure.rb', line 25 def self.fail!(type, message: nil, errors: nil) throw FAILURE, new( type, message:, errors: ) end |
.new(type, message: nil, errors: nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/openapi_first/failure.rb', line 36 def self.new(type, message: nil, errors: nil) unless TYPES.key?(type) raise ArgumentError, "type must be one of #{TYPES.keys} but was #{type.inspect}" end super(type:, message:, errors:) end |
Instance Method Details
#errors([Array<OpenapiFirst: :Schema::ValidationError>, nil]) ⇒ Object
49 |
# File 'lib/openapi_first/failure.rb', line 49 alias |
#exception(context = nil) ⇒ Object
57 58 59 |
# File 'lib/openapi_first/failure.rb', line 57 def exception(context = nil) TYPES.fetch(type).first.new(, context) end |
#exception_message ⇒ Object
61 62 63 64 65 |
# File 'lib/openapi_first/failure.rb', line 61 def _, = TYPES.fetch(type) [, || ].compact.join(' ') end |
#message ⇒ Object
A generic error message
53 54 55 |
# File 'lib/openapi_first/failure.rb', line 53 def || end |
#type([Symbol]) ⇒ Object
Example: :invalid_body
|
|
# File 'lib/openapi_first/failure.rb', line 44
|