@@ -281,7 +281,6 @@ def parse_fields(resource_klass, fields)
281281 fail JSONAPI ::Exceptions ::InvalidFieldFormat . new ( error_object_overrides )
282282 end
283283
284- errors = [ ]
285284 # Validate the fields
286285 validated_fields = { }
287286 extracted_fields . each do |type , values |
@@ -293,31 +292,27 @@ def parse_fields(resource_klass, fields)
293292 end
294293 type_resource = Resource . resource_klass_for ( resource_klass . module_path + underscored_type . to_s )
295294 rescue NameError
296- errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type , error_object_overrides ) . errors )
297- rescue JSONAPI ::Exceptions ::InvalidResource => e
298- errors . concat ( e . errors )
295+ fail JSONAPI ::Exceptions ::InvalidResource . new ( type , error_object_overrides )
299296 end
300297
301298 if type_resource . nil?
302- errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type , error_object_overrides ) . errors )
299+ fail JSONAPI ::Exceptions ::InvalidResource . new ( type , error_object_overrides )
303300 else
304301 unless values . nil?
305302 valid_fields = type_resource . fields . collect { |key | format_key ( key ) }
306303 values . each do |field |
307304 if valid_fields . include? ( field )
308305 validated_fields [ type ] . push unformat_key ( field )
309306 else
310- errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , field , error_object_overrides ) . errors )
307+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , field , error_object_overrides )
311308 end
312309 end
313310 else
314- errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' , error_object_overrides ) . errors )
311+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' , error_object_overrides )
315312 end
316313 end
317314 end
318315
319- fail JSONAPI ::Exceptions ::Errors . new ( errors ) unless errors . empty?
320-
321316 validated_fields . deep_transform_keys { |key | unformat_key ( key ) }
322317 end
323318
@@ -331,8 +326,7 @@ def check_include(resource_klass, include_parts)
331326 include_parts . last . partition ( '.' ) )
332327 end
333328 else
334- @errors . concat ( JSONAPI ::Exceptions ::InvalidInclude . new ( format_key ( resource_klass . _type ) ,
335- include_parts . first ) . errors )
329+ fail JSONAPI ::Exceptions ::InvalidInclude . new ( format_key ( resource_klass . _type ) , include_parts . first )
336330 end
337331 end
338332
@@ -352,12 +346,17 @@ def parse_include_directives(resource_klass, raw_include)
352346
353347 return if included_resources . nil?
354348
355- result = included_resources . compact . map do |included_resource |
356- check_include ( resource_klass , included_resource . partition ( '.' ) )
357- unformat_key ( included_resource ) . to_s
358- end
349+ begin
350+ result = included_resources . compact . map do |included_resource |
351+ check_include ( resource_klass , included_resource . partition ( '.' ) )
352+ unformat_key ( included_resource ) . to_s
353+ end
359354
360- JSONAPI ::IncludeDirectives . new ( resource_klass , result )
355+ return JSONAPI ::IncludeDirectives . new ( resource_klass , result )
356+ rescue JSONAPI ::Exceptions ::InvalidInclude => e
357+ @errors . concat ( e . errors )
358+ return { }
359+ end
361360 end
362361
363362 def parse_filters ( resource_klass , filters )
@@ -385,7 +384,7 @@ def parse_filters(resource_klass, filters)
385384 if resource_klass . _allowed_filter? ( filter )
386385 parsed_filters [ filter ] = value
387386 else
388- @errors . concat ( JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter ) . errors )
387+ fail JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter )
389388 end
390389 end
391390
@@ -428,8 +427,7 @@ def check_sort_criteria(resource_klass, sort_criteria)
428427 sort_field = sort_criteria [ :field ]
429428
430429 unless resource_klass . sortable_field? ( sort_field . to_sym , context )
431- @errors . concat ( JSONAPI ::Exceptions ::InvalidSortCriteria
432- . new ( format_key ( resource_klass . _type ) , sort_field ) . errors )
430+ fail JSONAPI ::Exceptions ::InvalidSortCriteria . new ( format_key ( resource_klass . _type ) , sort_field )
433431 end
434432 end
435433
@@ -578,16 +576,14 @@ def unformat_value(resource_klass, attribute, value)
578576 def verify_permitted_params ( params , allowed_fields )
579577 formatted_allowed_fields = allowed_fields . collect { |field | format_key ( field ) . to_sym }
580578 params_not_allowed = [ ]
581- param_errors = [ ]
582579
583580 params . each do |key , value |
584581 case key . to_s
585582 when 'relationships'
586583 value . keys . each do |links_key |
587584 unless formatted_allowed_fields . include? ( links_key . to_sym )
588585 if JSONAPI . configuration . raise_if_parameters_not_allowed
589- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
590- links_key , error_object_overrides ) . errors
586+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( links_key , error_object_overrides )
591587 else
592588 params_not_allowed . push ( links_key )
593589 value . delete links_key
@@ -598,8 +594,7 @@ def verify_permitted_params(params, allowed_fields)
598594 value . each do |attr_key , _attr_value |
599595 unless formatted_allowed_fields . include? ( attr_key . to_sym )
600596 if JSONAPI . configuration . raise_if_parameters_not_allowed
601- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
602- attr_key , error_object_overrides ) . errors
597+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( attr_key , error_object_overrides )
603598 else
604599 params_not_allowed . push ( attr_key )
605600 value . delete attr_key
@@ -610,27 +605,23 @@ def verify_permitted_params(params, allowed_fields)
610605 when 'id'
611606 unless formatted_allowed_fields . include? ( :id )
612607 if JSONAPI . configuration . raise_if_parameters_not_allowed
613- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
614- :id , error_object_overrides ) . errors
608+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :id , error_object_overrides )
615609 else
616610 params_not_allowed . push ( :id )
617611 params . delete :id
618612 end
619613 end
620614 else
621615 if JSONAPI . configuration . raise_if_parameters_not_allowed
622- param_errors += JSONAPI ::Exceptions ::ParameterNotAllowed . new (
623- key , error_object_overrides ) . errors
616+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( key , error_object_overrides )
624617 else
625618 params_not_allowed . push ( key )
626619 params . delete key
627620 end
628621 end
629622 end
630623
631- if param_errors . length > 0
632- fail JSONAPI ::Exceptions ::Errors . new ( param_errors )
633- elsif params_not_allowed . length > 0
624+ if params_not_allowed . length > 0
634625 params_not_allowed_warnings = params_not_allowed . map do |param |
635626 JSONAPI ::Warning . new ( code : JSONAPI ::PARAM_NOT_ALLOWED ,
636627 title : 'Param not allowed' ,
0 commit comments