@@ -10,8 +10,7 @@ def self.included(base)
10
10
base . include Callbacks
11
11
base . cattr_reader :server_error_callbacks
12
12
base . define_jsonapi_resources_callbacks :process_operations ,
13
- :transaction ,
14
- :rollback
13
+ :transaction
15
14
end
16
15
17
16
attr_reader :response_document
@@ -76,57 +75,46 @@ def process_request
76
75
77
76
transactional = request_parser . transactional?
78
77
79
- force_rollback = false
80
- run_in_transaction ( transactional ) do
81
- begin
78
+ begin
79
+ run_in_transaction ( transactional ) do
82
80
run_callbacks :process_operations do
83
- begin
84
- request_parser . each ( response_document ) do |op |
85
- op . options [ :serializer ] = resource_serializer_klass . new (
86
- op . resource_klass ,
87
- include_directives : op . options [ :include_directives ] ,
88
- fields : op . options [ :fields ] ,
89
- base_url : base_url ,
90
- key_formatter : key_formatter ,
91
- route_formatter : route_formatter ,
92
- serialization_options : serialization_options
93
- )
94
- op . options [ :cache_serializer_output ] = !JSONAPI . configuration . resource_cache . nil?
95
-
96
- process_operation ( op )
97
- end
98
- rescue => e
99
- handle_exceptions ( e )
81
+ request_parser . each ( response_document ) do |op |
82
+ op . options [ :serializer ] = resource_serializer_klass . new (
83
+ op . resource_klass ,
84
+ include_directives : op . options [ :include_directives ] ,
85
+ fields : op . options [ :fields ] ,
86
+ base_url : base_url ,
87
+ key_formatter : key_formatter ,
88
+ route_formatter : route_formatter ,
89
+ serialization_options : serialization_options
90
+ )
91
+ op . options [ :cache_serializer_output ] = !JSONAPI . configuration . resource_cache . nil?
92
+
93
+ process_operation ( op )
100
94
end
101
95
end
102
- rescue => e
103
- force_rollback = true
104
- raise e
105
- ensure
106
- if response_document . has_errors? || force_rollback
107
- rollback_transaction ( transactional )
96
+ if response_document . has_errors?
97
+ raise ActiveRecord ::Rollback
108
98
end
109
99
end
100
+ rescue => e
101
+ handle_exceptions ( e )
110
102
end
111
103
render_response_document
112
104
end
113
105
114
106
def run_in_transaction ( transactional )
115
107
if transactional
116
108
run_callbacks :transaction do
117
- transaction do
109
+ ActiveRecord :: Base . transaction do
118
110
yield
119
111
end
120
112
end
121
113
else
122
- yield
123
- end
124
- end
125
-
126
- def rollback_transaction ( transactional )
127
- if transactional
128
- run_callbacks :rollback do
129
- rollback
114
+ begin
115
+ yield
116
+ rescue ActiveRecord ::Rollback
117
+ # Can't rollback without transaction, so just ignore it
130
118
end
131
119
end
132
120
end
@@ -136,16 +124,6 @@ def process_operation(operation)
136
124
response_document . add_result ( result , operation )
137
125
end
138
126
139
- def transaction
140
- ActiveRecord ::Base . transaction do
141
- yield
142
- end
143
- end
144
-
145
- def rollback
146
- fail ActiveRecord ::Rollback
147
- end
148
-
149
127
private
150
128
151
129
def resource_klass
@@ -276,7 +254,7 @@ def handle_exceptions(e)
276
254
errors = JSONAPI ::Exceptions ::ParameterMissing . new ( e . param ) . errors
277
255
else
278
256
if JSONAPI . configuration . exception_class_whitelisted? ( e )
279
- fail e
257
+ raise e
280
258
else
281
259
if self . class . server_error_callbacks
282
260
self . class . server_error_callbacks . each { |callback |
0 commit comments