@@ -281,7 +281,6 @@ def parse_fields(resource_klass, fields)
281
281
fail JSONAPI ::Exceptions ::InvalidFieldFormat . new ( error_object_overrides )
282
282
end
283
283
284
- errors = [ ]
285
284
# Validate the fields
286
285
validated_fields = { }
287
286
extracted_fields . each do |type , values |
@@ -293,31 +292,27 @@ def parse_fields(resource_klass, fields)
293
292
end
294
293
type_resource = Resource . resource_klass_for ( resource_klass . module_path + underscored_type . to_s )
295
294
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 )
299
296
end
300
297
301
298
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 )
303
300
else
304
301
unless values . nil?
305
302
valid_fields = type_resource . fields . collect { |key | format_key ( key ) }
306
303
values . each do |field |
307
304
if valid_fields . include? ( field )
308
305
validated_fields [ type ] . push unformat_key ( field )
309
306
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 )
311
308
end
312
309
end
313
310
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 )
315
312
end
316
313
end
317
314
end
318
315
319
- fail JSONAPI ::Exceptions ::Errors . new ( errors ) unless errors . empty?
320
-
321
316
validated_fields . deep_transform_keys { |key | unformat_key ( key ) }
322
317
end
323
318
@@ -389,7 +384,7 @@ def parse_filters(resource_klass, filters)
389
384
if resource_klass . _allowed_filter? ( filter )
390
385
parsed_filters [ filter ] = value
391
386
else
392
- @errors . concat ( JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter ) . errors )
387
+ fail JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter )
393
388
end
394
389
end
395
390
@@ -432,8 +427,7 @@ def check_sort_criteria(resource_klass, sort_criteria)
432
427
sort_field = sort_criteria [ :field ]
433
428
434
429
unless resource_klass . sortable_field? ( sort_field . to_sym , context )
435
- @errors . concat ( JSONAPI ::Exceptions ::InvalidSortCriteria
436
- . new ( format_key ( resource_klass . _type ) , sort_field ) . errors )
430
+ fail JSONAPI ::Exceptions ::InvalidSortCriteria . new ( format_key ( resource_klass . _type ) , sort_field )
437
431
end
438
432
end
439
433
@@ -582,16 +576,14 @@ def unformat_value(resource_klass, attribute, value)
582
576
def verify_permitted_params ( params , allowed_fields )
583
577
formatted_allowed_fields = allowed_fields . collect { |field | format_key ( field ) . to_sym }
584
578
params_not_allowed = [ ]
585
- param_errors = [ ]
586
579
587
580
params . each do |key , value |
588
581
case key . to_s
589
582
when 'relationships'
590
583
value . keys . each do |links_key |
591
584
unless formatted_allowed_fields . include? ( links_key . to_sym )
592
585
if JSONAPI . configuration . raise_if_parameters_not_allowed
593
- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
594
- links_key , error_object_overrides ) . errors
586
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( links_key , error_object_overrides )
595
587
else
596
588
params_not_allowed . push ( links_key )
597
589
value . delete links_key
@@ -602,8 +594,7 @@ def verify_permitted_params(params, allowed_fields)
602
594
value . each do |attr_key , _attr_value |
603
595
unless formatted_allowed_fields . include? ( attr_key . to_sym )
604
596
if JSONAPI . configuration . raise_if_parameters_not_allowed
605
- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
606
- attr_key , error_object_overrides ) . errors
597
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( attr_key , error_object_overrides )
607
598
else
608
599
params_not_allowed . push ( attr_key )
609
600
value . delete attr_key
@@ -614,27 +605,23 @@ def verify_permitted_params(params, allowed_fields)
614
605
when 'id'
615
606
unless formatted_allowed_fields . include? ( :id )
616
607
if JSONAPI . configuration . raise_if_parameters_not_allowed
617
- param_errors . concat JSONAPI ::Exceptions ::ParameterNotAllowed . new (
618
- :id , error_object_overrides ) . errors
608
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :id , error_object_overrides )
619
609
else
620
610
params_not_allowed . push ( :id )
621
611
params . delete :id
622
612
end
623
613
end
624
614
else
625
615
if JSONAPI . configuration . raise_if_parameters_not_allowed
626
- param_errors += JSONAPI ::Exceptions ::ParameterNotAllowed . new (
627
- key , error_object_overrides ) . errors
616
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( key , error_object_overrides )
628
617
else
629
618
params_not_allowed . push ( key )
630
619
params . delete key
631
620
end
632
621
end
633
622
end
634
623
635
- if param_errors . length > 0
636
- fail JSONAPI ::Exceptions ::Errors . new ( param_errors )
637
- elsif params_not_allowed . length > 0
624
+ if params_not_allowed . length > 0
638
625
params_not_allowed_warnings = params_not_allowed . map do |param |
639
626
JSONAPI ::Warning . new ( code : JSONAPI ::PARAM_NOT_ALLOWED ,
640
627
title : 'Param not allowed' ,
0 commit comments