Module: OpenapiFirst::ErrorResponse

Included in:
OpenapiFirst::ErrorResponses::Default, OpenapiFirst::ErrorResponses::Jsonapi
Defined in:
lib/openapi_first/error_response.rb

Overview

This is the base module for error responses

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failureObject (readonly)

Returns the value of attribute failure.



11
12
13
# File 'lib/openapi_first/error_response.rb', line 11

def failure
  @failure
end

Instance Method Details

#bodyObject

The response body



14
15
16
# File 'lib/openapi_first/error_response.rb', line 14

def body
  raise "#{self.class} must implement the method #{__method__}"
end

#content_typeObject

The response content-type



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

def content_type
  raise "#{self.class} must implement the method #{__method__}"
end

#initialize(failure: nil) ⇒ Object

Parameters:



7
8
9
# File 'lib/openapi_first/error_response.rb', line 7

def initialize(failure: nil)
  @failure = failure
end

#renderObject

Render this error response



36
37
38
# File 'lib/openapi_first/error_response.rb', line 36

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

#statusObject

The response status



31
32
33
# File 'lib/openapi_first/error_response.rb', line 31

def status
  STATUS[failure.type] || 400
end