class Praxis::Responses::ValidationError

Public Class Methods

new(summary:, errors: nil, exception: nil, documentation: nil, **opts) click to toggle source
Calls superclass method Praxis::Response::new
# File lib/praxis/responses/validation_error.rb, line 6
def initialize(summary:, errors: nil, exception: nil, documentation: 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.message] if exception && exception.message
   end
  @exception = exception
  @summary = summary
  @documentation = documentation
end

Public Instance Methods

format!() click to toggle source
# File lib/praxis/responses/validation_error.rb, line 18
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.message}
  end

  @body[:documentation] = @documentation if @documentation

  @body
end