Class: Onsi::ErrorResponse
- Inherits:
-
Object
- Object
- Onsi::ErrorResponse
- Defined in:
- lib/onsi/error_responder.rb
Overview
The error response container.
Instance Attribute Summary collapse
-
#status ⇒ Integer
readonly
The HTTP status for the response.
Instance Method Summary collapse
-
#add(status, code, title: nil, details: nil, meta: nil) ⇒ Object
Add a renderable error to the errors.
-
#as_json ⇒ Hash
Create the error objects.
-
#initialize(status) ⇒ ErrorResponse
constructor
Create a new ErrorResponse.
Constructor Details
#initialize(status) ⇒ ErrorResponse
Create a new ErrorResponse
196 197 198 199 |
# File 'lib/onsi/error_responder.rb', line 196 def initialize(status) @status = status @errors = [] end |
Instance Attribute Details
#status ⇒ Integer (readonly)
The HTTP status for the response.
190 191 192 |
# File 'lib/onsi/error_responder.rb', line 190 def status @status end |
Instance Method Details
#add(status, code, title: nil, details: nil, meta: nil) ⇒ Object
Add a renderable error to the errors
215 216 217 218 219 220 221 222 223 |
# File 'lib/onsi/error_responder.rb', line 215 def add(status, code, title: nil, details: nil, meta: nil) @errors << {}.tap do |err| err[:status] = (status || @status).to_s err[:code] = code err[:title] = title if title.present? err[:detail] = details if details.present? err[:meta] = Hash() if .present? end end |
#as_json ⇒ Hash
Create the error objects.
229 230 231 |
# File 'lib/onsi/error_responder.rb', line 229 def as_json { errors: @errors.as_json } end |