lib/jsonapionify/api/resource/definitions/request_headers.rb in jsonapionify-0.9.0 vs lib/jsonapionify/api/resource/definitions/request_headers.rb in jsonapionify-0.9.1

- old
+ new

@@ -4,26 +4,29 @@ def self.extended(klass) klass.class_eval do extend JSONAPIonify::InheritedAttributes inherited_hash_attribute :request_header_definitions - context(:request_headers) do |context| + context(:request_headers, persisted: true, readonly: true) do |context| should_error = false # Check for validity headers = self.class.request_header_definitions.select do |_, v| v.actions.blank? || v.actions.include?(action_name) end required_headers = headers.select do |_, v| v.required end - if (missing_keys = required_headers.keys.map(&:downcase) - context.request.headers.keys.map(&:downcase)).present? + missing_keys = + required_headers.keys.map(&:downcase) - + context.request.headers.keys.map(&:downcase) + if context.root_request? && missing_keys.present? should_error = true error :headers_missing, missing_keys end - raise Errors::RequestError if should_error + halt if should_error context.request.headers end end end