@@ -827,33 +827,64 @@ defmodule Mongo do
827
827
end
828
828
end
829
829
830
+ ##
831
+ # Checks for an error and broadcast the event.
832
+ ##
833
+ defp check_for_error ( { % { "ok" => ok } = response , % { request_id: request_id , operation_id: operation_id , connection_id: connection_id } = event , flags , duration } ) when ok == 1 do
834
+ Events . notify (
835
+ % CommandSucceededEvent {
836
+ reply: response ,
837
+ duration: duration ,
838
+ command_name: event . command_name ,
839
+ request_id: request_id ,
840
+ operation_id: operation_id ,
841
+ connection_id: connection_id
842
+ } ,
843
+ :commands
844
+ )
845
+
846
+ { :ok , { flags , response } }
847
+ end
848
+
830
849
defp check_for_error ( { % { "ok" => ok } = response , event , flags , duration } ) when ok == 1 do
831
850
Events . notify (
832
851
% CommandSucceededEvent {
833
852
reply: response ,
834
853
duration: duration ,
835
- command_name: event . command_name , ## todo
836
- #request_id: event.request_id,
837
- #operation_id: event.operation_id,
838
- #connection_id: event.connection_id
854
+ command_name: event . command_name
839
855
} ,
840
856
:commands
841
857
)
842
858
843
859
{ :ok , { flags , response } }
844
860
end
845
861
846
- defp check_for_error ( { doc , event , _flags , duration } ) do
862
+ defp check_for_error ( { doc , % { request_id: request_id , operation_id: operation_id , connection_id: connection_id } = event , _flags , duration } ) do
847
863
error = Mongo.Error . exception ( doc )
848
864
849
865
Events . notify (
850
866
% CommandFailedEvent {
851
867
failure: error ,
852
868
duration: duration ,
853
869
command_name: event . command_name ,
854
- #request_id: event.request_id,
855
- #operation_id: event.operation_id,
856
- #connection_id: event.connection_id
870
+ request_id: request_id ,
871
+ operation_id: operation_id ,
872
+ connection_id: connection_id
873
+ } ,
874
+ :commands
875
+ )
876
+
877
+ { :error , error }
878
+ end
879
+
880
+ defp check_for_error ( { doc , event , _flags , duration } ) do
881
+ error = Mongo.Error . exception ( doc )
882
+
883
+ Events . notify (
884
+ % CommandFailedEvent {
885
+ failure: error ,
886
+ duration: duration ,
887
+ command_name: event . command_name
857
888
} ,
858
889
:commands
859
890
)
0 commit comments