Class: Pragma::Operation::Response::UnprocessableEntity
- Inherits:
-
Pragma::Operation::Response
- Object
- Pragma::Operation::Response
- Pragma::Operation::Response::UnprocessableEntity
- Defined in:
- lib/pragma/operation/response/unprocessable_entity.rb
Overview
Represents the 422 Unprocessable Entity HTTP response.
Constant Summary
Constants inherited from Pragma::Operation::Response
Instance Attribute Summary
Attributes inherited from Pragma::Operation::Response
Instance Method Summary collapse
-
#initialize(entity: nil, headers: {}, errors: nil) ⇒ UnprocessableEntity
constructor
Initializes the response.
Methods inherited from Pragma::Operation::Response
#decorate_with, #failure?, #success?
Constructor Details
#initialize(entity: nil, headers: {}, errors: nil) ⇒ UnprocessableEntity
Initializes the response.
You can provide either entity or errors, but not both. If you provide entity, the standard response’s entity will be replaced with yours. If you provide errors, the standard entity will be used and your errors will be added to the meta.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pragma/operation/response/unprocessable_entity.rb', line 19 def initialize(entity: nil, headers: {}, errors: nil) fail ArgumentError, 'You cannot provide both :entity and :errors!' if entity && errors entity ||= Error.new( error_type: :unprocessable_entity, error_message: 'The provided resource is in an unexpected format.', meta: { errors: errors || {} } ) super(status: 422, entity: entity, headers: headers) end |