Module: OpenapiFirst::ErrorResponse

Included in:
Plugins::Default::ErrorResponse, Plugins::Jsonapi::ErrorResponse
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

Raises:

  • (NotImplementedError)


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

def body
  raise NotImplementedError
end

#content_typeObject

The response content-type

Raises:

  • (NotImplementedError)


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

def content_type
  raise NotImplementedError
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