lib/isomorfeus/operation/handler/operation_handler.rb in isomorfeus-operation-1.0.0.zeta14 vs lib/isomorfeus/operation/handler/operation_handler.rb in isomorfeus-operation-1.0.0.zeta15
- old
+ new
@@ -8,17 +8,23 @@
# promise_send_path('Isomorfeus::Operation::Handler::OperationHandler', self.to_s, props_hash)
response_agent.request.each_key do |operation_class_name|
if Isomorfeus.valid_operation_class_name?(operation_class_name)
operation_class = Isomorfeus.cached_operation_class(operation_class_name)
if operation_class
- props_json = response_agent.request[operation_class_name]
+ props = response_agent.request[operation_class_name]
+ props.transform_keys!(&:to_sym)
begin
- props = Oj.load(props_json, mode: :strict)
if Isomorfeus.current_user.authorized?(operation_class, :promise_run, props)
- operation_promise = operation_class.promise_run(props)
+ operation_promise = operation_class.promise_run(**props)
if operation_promise.realized?
- response_agent.agent_result = { success: 'ok' , result: operation_promise.value }
+ state = operation_promise.resolved? ? :resolved : :rejected
+ result_hash = { state => operation_promise.value }
+ if operation_promise.error
+ e = operation_promise.error
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
+ end
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
else
start = Time.now
timeout = false
while !operation_promise.realized?
if (Time.now - start) > 20
@@ -28,10 +34,16 @@
sleep 0.01
end
if timeout
response_agent.error = { error: 'Timeout' }
else
- response_agent.agent_result = { success: 'ok' , result: operation_promise.value }
+ state = operation_promise.resolved? ? :resolved : :rejected
+ result_hash = { state => operation_promise.value }
+ if operation_promise.error
+ e = operation_promise.error
+ result_hash[:error] = { message: e.message, class_name: e.class.to_s, back_trace: e.backtrace }
+ end
+ response_agent.agent_result = { success: 'ok' , result: result_hash }
end
end
else
response_agent.error = { error: 'Access denied!' }
end