Sha256: 7c0ffef6a385dccbcf91bf5465a01e2b72317786f8395ca3c484aed1ec29ec28
Contents?: true
Size: 1.24 KB
Versions: 19
Compression:
Stored size: 1.24 KB
Contents
module Praxis module Responses class ValidationError < BadRequest 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 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 end end ApiDefinition.define do |api| api.response_template :validation_error do description "An error message indicating that one or more elements of the request did not match the API specification for the action" status 400 media_type "application/json" end end end
Version data entries
19 entries across 19 versions & 1 rubygems