Class: Praxis::Responses::ValidationError
- Inherits:
-
BadRequest
- Object
- Praxis::Response
- BadRequest
- Praxis::Responses::ValidationError
- Defined in:
- lib/praxis/responses/validation_error.rb
Instance Attribute Summary
Attributes inherited from Praxis::Response
#body, #headers, #name, #parts, #request, #status
Instance Method Summary collapse
- #format! ⇒ Object
-
#initialize(summary:, errors: nil, exception: nil, **opts) ⇒ ValidationError
constructor
A new instance of ValidationError.
Methods inherited from Praxis::Response
#add_part, #content_type, #content_type=, #encode!, #finish, #handle, inherited, #response_name, #validate
Constructor Details
#initialize(summary:, errors: nil, exception: nil, **opts) ⇒ ValidationError
Returns a new instance of ValidationError.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/praxis/responses/validation_error.rb', line 6 def initialize(summary:, errors: nil, exception: nil, **opts) super(**opts) @headers['Content-Type'] = 'application/json' #TODO: might want an error mediatype @errors = errors unless @errors # The exception message will the the only error if no errors are passed in @errors = [exception.] if exception && exception. end @exception = exception @summary = summary end |
Instance Method Details
#format! ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/praxis/responses/validation_error.rb', line 17 def format! @body = {name: 'ValidationError', summary: @summary } @body[:errors] = @errors if @errors if @exception && @exception.cause @body[:cause] = {name: @exception.cause.class.name, message: @exception.cause.} end @body end |