lib/jsonapi/operations_processor.rb in jsonapi-resources-0.4.2 vs lib/jsonapi/operations_processor.rb in jsonapi-resources-0.4.3

- old
+ new

@@ -10,10 +10,11 @@ :show_related_resources_operation, :create_resource_operation, :remove_resource_operation, :replace_fields_operation, :replace_has_one_association_operation, + :replace_polymorphic_has_one_association_operation, :create_has_many_association_operation, :replace_has_many_association_operation, :remove_has_many_association_operation, :remove_has_one_association_operation @@ -32,11 +33,11 @@ # Use transactions if more than one operation and if one of the operations can be transactional # Even if transactional transactions won't be used unless the derived OperationsProcessor supports them. @transactional = false if @operations.length > 1 @operations.each do |operation| - @transactional = @transactional | operation.transactional + @transactional |= operation.transactional end end run_callbacks :operations do transaction do @@ -54,13 +55,11 @@ @result = process_operation(@operation) end @result.meta.merge!(@operation_meta) @result.links.merge!(@operation_links) @results.add_result(@result) - if @results.has_errors? - rollback - end + rollback if @results.has_errors? end end @results.meta = @operations_meta @results.links = @operations_links end @@ -80,11 +79,23 @@ def rollback end def process_operation(operation) operation.apply + + rescue JSONAPI::Exceptions::Error => e + # :nocov: + raise e + # :nocov: + + rescue => e + # :nocov: + internal_server_error = JSONAPI::Exceptions::InternalServerError.new(e) + Rails.logger.error { "Internal Server Error: #{e.message} #{e.backtrace.join("\n")}" } + return JSONAPI::ErrorsOperationResult.new(internal_server_error.errors[0].code, internal_server_error.errors) + # :nocov: end end end class BasicOperationsProcessor < JSONAPI::OperationsProcessor -end \ No newline at end of file +end