Class: OpenapiFirst::ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/error_response.rb

Overview

This is the base class for error responses

Direct Known Subclasses

DefaultErrorResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, location:, title:, validation_result:) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.

Parameters:

  • status (Integer)

    The HTTP status code.

  • title (String)

    The title of the error. Usually the name of the HTTP status code.

  • location (Symbol)

    The location of the error (:request_body, :query, :header, :cookie, :path).

  • validation_result (ValidationResult)


10
11
12
13
14
15
16
17
# File 'lib/openapi_first/error_response.rb', line 10

def initialize(status:, location:, title:, validation_result:)
  @status = status
  @title = title
  @location = location
  @validation_output = validation_result&.output
  @schema = validation_result&.schema
  @data = validation_result&.data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def data
  @data
end

#locationObject (readonly)

Returns the value of attribute location.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def location
  @location
end

#schemaObject (readonly)

Returns the value of attribute schema.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def schema
  @schema
end

#statusObject (readonly)

Returns the value of attribute status.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def title
  @title
end

#validation_outputObject (readonly)

Returns the value of attribute validation_output.



19
20
21
# File 'lib/openapi_first/error_response.rb', line 19

def validation_output
  @validation_output
end

Instance Method Details

#bodyObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/openapi_first/error_response.rb', line 27

def body
  raise NotImplementedError
end

#content_typeObject



25
# File 'lib/openapi_first/error_response.rb', line 25

def content_type = 'application/json'

#renderObject



21
22
23
# File 'lib/openapi_first/error_response.rb', line 21

def render
  Rack::Response.new(body, status, Rack::CONTENT_TYPE => content_type).finish
end