@@ -170,25 +170,23 @@ def parse_fields(fields)
170
170
end
171
171
type_resource = Resource . resource_for ( @resource_klass . module_path + underscored_type . to_s )
172
172
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 )
176
174
end
177
175
178
176
if type_resource . nil?
179
- @errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type ) . errors )
177
+ fail JSONAPI ::Exceptions ::InvalidResource . new ( type )
180
178
else
181
179
unless values . nil?
182
180
valid_fields = type_resource . fields . collect { |key | format_key ( key ) }
183
181
values . each do |field |
184
182
if valid_fields . include? ( field )
185
183
extracted_fields [ type ] . push unformat_key ( field )
186
184
else
187
- @errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , field ) . errors )
185
+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , field )
188
186
end
189
187
end
190
188
else
191
- @errors . concat ( JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' ) . errors )
189
+ fail JSONAPI ::Exceptions ::InvalidField . new ( type , 'nil' )
192
190
end
193
191
end
194
192
end
@@ -213,7 +211,7 @@ def parse_include_directives(raw_include)
213
211
return unless raw_include
214
212
215
213
unless JSONAPI . configuration . allow_include
216
- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :include ] )
214
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :include )
217
215
end
218
216
219
217
included_resources = [ ]
@@ -242,7 +240,7 @@ def parse_filters(filters)
242
240
return unless filters
243
241
244
242
unless JSONAPI . configuration . allow_filter
245
- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :filter ] )
243
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :filter )
246
244
end
247
245
248
246
unless filters . class . method_defined? ( :each )
@@ -255,7 +253,7 @@ def parse_filters(filters)
255
253
if @resource_klass . _allowed_filter? ( filter )
256
254
@filters [ filter ] = value
257
255
else
258
- @errors . concat ( JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter ) . errors )
256
+ fail JSONAPI ::Exceptions ::FilterNotAllowed . new ( filter )
259
257
end
260
258
end
261
259
end
@@ -271,7 +269,7 @@ def parse_sort_criteria(sort_criteria)
271
269
return unless sort_criteria . present?
272
270
273
271
unless JSONAPI . configuration . allow_sort
274
- fail JSONAPI ::Exceptions ::ParametersNotAllowed . new ( [ :sort ] )
272
+ fail JSONAPI ::Exceptions ::ParameterNotAllowed . new ( :sort )
275
273
end
276
274
277
275
sorts = [ ]
@@ -300,9 +298,8 @@ def check_sort_criteria(resource_klass, sort_criteria)
300
298
sort_field = sort_criteria [ :field ]
301
299
sortable_fields = resource_klass . sortable_fields ( context )
302
300
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 )
306
303
end
307
304
end
308
305
@@ -532,45 +529,52 @@ def verify_permitted_params(params, allowed_fields)
532
529
when 'relationships'
533
530
value . keys . each do |links_key |
534
531
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 )
537
536
value . delete links_key
538
537
end
539
538
end
540
539
end
541
540
when 'attributes'
542
541
value . each do |attr_key , attr_value |
543
542
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 )
546
547
value . delete attr_key
547
548
end
548
549
end
549
550
end
550
551
when 'type'
551
552
when 'id'
552
553
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 )
555
558
params . delete :id
556
559
end
557
560
end
558
561
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
560
568
end
561
569
end
562
570
563
571
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." )
573
576
end
577
+ self . warnings . concat ( params_not_allowed_warnings )
574
578
end
575
579
end
576
580
0 commit comments