@@ -170,25 +170,23 @@ def parse_fields(fields)
170170 end
171171 type_resource = Resource . resource_for ( @resource_klass . module_path + underscored_type . to_s )
172172 rescue NameError
173- @errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type ) . errors )
174- rescue JSONAPI ::Exceptions ::InvalidResource => e
175- @errors . concat ( e . errors )
173+ fail JSONAPI ::Exceptions ::InvalidResource . new ( type )
176174 end
177175
178176 if type_resource . nil?
179- @errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type ) . errors )
177+ fail JSONAPI ::Exceptions ::InvalidResource . new ( type )
180178 else
181179 unless values . nil?
182180 valid_fields = type_resource . fields . collect { |key | format_key ( key ) }
183181 values . each do |field |
184182 if valid_fields . include? ( field )
185183 extracted_fields [ type ] . push unformat_key ( field )
186184 else
187- @errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , field ) . errors )
185+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , field )
188186 end
189187 end
190188 else
191- @errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' ) . errors )
189+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' )
192190 end
193191 end
194192 end
@@ -213,7 +211,7 @@ def parse_include_directives(raw_include)
213211 return unless raw_include
214212
215213 unless JSONAPI . configuration . allow_include
216- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :include ] )
214+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :include )
217215 end
218216
219217 included_resources = [ ]
@@ -242,7 +240,7 @@ def parse_filters(filters)
242240 return unless filters
243241
244242 unless JSONAPI . configuration . allow_filter
245- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :filter ] )
243+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :filter )
246244 end
247245
248246 unless filters . class . method_defined? ( :each )
@@ -255,7 +253,7 @@ def parse_filters(filters)
255253 if @resource_klass . _allowed_filter? ( filter )
256254 @filters [ filter ] = value
257255 else
258- @errors . concat ( JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter ) . errors )
256+ fail JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter )
259257 end
260258 end
261259 end
@@ -271,7 +269,7 @@ def parse_sort_criteria(sort_criteria)
271269 return unless sort_criteria . present?
272270
273271 unless JSONAPI . configuration . allow_sort
274- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :sort ] )
272+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :sort )
275273 end
276274
277275 sorts = [ ]
@@ -300,9 +298,8 @@ def check_sort_criteria(resource_klass, sort_criteria)
300298 sort_field = sort_criteria [ :field ]
301299 sortable_fields = resource_klass . sortable_fields ( context )
302300
303- unless sortable_fields . include? sort_field . to_sym
304- @errors . concat ( JSONAPI ::Exceptions ::InvalidSortCriteria
305- . new ( format_key ( resource_klass . _type ) , sort_field ) . errors )
301+ unless sortable_fields . include? sort_field . to_sym
302+ fail JSONAPI ::Exceptions ::InvalidSortCriteria . new ( format_key ( resource_klass . _type ) , sort_field )
306303 end
307304 end
308305
@@ -532,45 +529,52 @@ def verify_permitted_params(params, allowed_fields)
532529 when 'relationships'
533530 value . keys . each do |links_key |
534531 unless formatted_allowed_fields . include? ( links_key . to_sym )
535- params_not_allowed . push ( links_key )
536- unless JSONAPI . configuration . raise_if_parameters_not_allowed
532+ if JSONAPI . configuration . raise_if_parameters_not_allowed
533+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( links_key )
534+ else
535+ params_not_allowed . push ( links_key )
537536 value . delete links_key
538537 end
539538 end
540539 end
541540 when 'attributes'
542541 value . each do |attr_key , attr_value |
543542 unless formatted_allowed_fields . include? ( attr_key . to_sym )
544- params_not_allowed . push ( attr_key )
545- unless JSONAPI . configuration . raise_if_parameters_not_allowed
543+ if JSONAPI . configuration . raise_if_parameters_not_allowed
544+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( attr_key )
545+ else
546+ params_not_allowed . push ( attr_key )
546547 value . delete attr_key
547548 end
548549 end
549550 end
550551 when 'type'
551552 when 'id'
552553 unless formatted_allowed_fields . include? ( :id )
553- params_not_allowed . push ( :id )
554- unless JSONAPI . configuration . raise_if_parameters_not_allowed
554+ if JSONAPI . configuration . raise_if_parameters_not_allowed
555+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :id )
556+ else
557+ params_not_allowed . push ( :id )
555558 params . delete :id
556559 end
557560 end
558561 else
559- params_not_allowed . push ( key )
562+ if JSONAPI . configuration . raise_if_parameters_not_allowed
563+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( key )
564+ else
565+ params_not_allowed . push ( key )
566+ params . delete key
567+ end
560568 end
561569 end
562570
563571 if params_not_allowed . length > 0
564- if JSONAPI . configuration . raise_if_parameters_not_allowed
565- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( params_not_allowed )
566- else
567- params_not_allowed_warnings = params_not_allowed . map do |key |
568- JSONAPI ::Warning . new ( code : JSONAPI ::PARAM_NOT_ALLOWED ,
569- title : 'Param not allowed' ,
570- detail : "#{ key } is not allowed." )
571- end
572- self . warnings . concat ( params_not_allowed_warnings )
572+ params_not_allowed_warnings = params_not_allowed . map do |param |
573+ JSONAPI ::Warning . new ( code : JSONAPI ::PARAM_NOT_ALLOWED ,
574+ title : 'Param not allowed' ,
575+ detail : "#{ param } is not allowed." )
573576 end
577+ self . warnings . concat ( params_not_allowed_warnings )
574578 end
575579 end
576580
0 commit comments