1111
1212namespace GraphAware \Neo4j \Client \Transaction ;
1313
14+ use GraphAware \Bolt \Exception \MessageFailureException ;
1415use GraphAware \Common \Cypher \Statement ;
1516use GraphAware \Common \Result \Result ;
1617use GraphAware \Common \Transaction \TransactionInterface ;
18+ use GraphAware \Neo4j \Client \Event \FailureEvent ;
1719use GraphAware \Neo4j \Client \Event \PostRunEvent ;
1820use GraphAware \Neo4j \Client \Event \PreRunEvent ;
21+ use GraphAware \Neo4j \Client \Exception \Neo4jException ;
1922use GraphAware \Neo4j \Client \Neo4jClientEvents ;
2023use GraphAware \Neo4j \Client \Result \ResultCollection ;
2124use GraphAware \Neo4j \Client \StackInterface ;
@@ -65,7 +68,9 @@ public function push($statement, array $parameters = [], $tag = null)
6568 * @param array $parameters
6669 * @param null|string $tag
6770 *
68- * @return \GraphAware\Common\Result\Result
71+ * @throws Neo4jException
72+ *
73+ * @return \GraphAware\Common\Result\Result|null
6974 */
7075 public function run ($ statement , array $ parameters = [], $ tag = null )
7176 {
@@ -74,8 +79,20 @@ public function run($statement, array $parameters = [], $tag = null)
7479 }
7580 $ stmt = Statement::create ($ statement , $ parameters , $ tag );
7681 $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_PRE_RUN , new PreRunEvent ([$ stmt ]));
77- $ result = $ this ->driverTransaction ->run (Statement::create ($ statement , $ parameters , $ tag ));
78- $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent (ResultCollection::withResult ($ result )));
82+ try {
83+ $ result = $ this ->driverTransaction ->run (Statement::create ($ statement , $ parameters , $ tag ));
84+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent (ResultCollection::withResult ($ result )));
85+ } catch (MessageFailureException $ e ) {
86+ $ exception = new Neo4jException ($ e ->getMessage ());
87+ $ exception ->setNeo4jStatusCode ($ e ->getStatusCode ());
88+
89+ $ event = new FailureEvent ($ exception );
90+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_ON_FAILURE , $ event );
91+ if ($ event ->shouldThrowException ()) {
92+ throw $ exception ;
93+ }
94+ return null ;
95+ }
7996
8097 return $ result ;
8198 }
@@ -93,7 +110,9 @@ public function pushStack(StackInterface $stack)
93110 /**
94111 * @param StackInterface $stack
95112 *
96- * @return ResultCollection|Result[]
113+ * @throws Neo4jException
114+ *
115+ * @return ResultCollection|Result[]|null
97116 */
98117 public function runStack (StackInterface $ stack )
99118 {
@@ -108,8 +127,20 @@ public function runStack(StackInterface $stack)
108127 }
109128
110129 $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_PRE_RUN , new PreRunEvent ($ stack ->statements ()));
111- $ results = $ this ->driverTransaction ->runMultiple ($ sts );
112- $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent ($ results ));
130+ try {
131+ $ results = $ this ->driverTransaction ->runMultiple ($ sts );
132+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_POST_RUN , new PostRunEvent ($ results ));
133+ } catch (MessageFailureException $ e ) {
134+ $ exception = new Neo4jException ($ e ->getMessage ());
135+ $ exception ->setNeo4jStatusCode ($ e ->getStatusCode ());
136+
137+ $ event = new FailureEvent ($ exception );
138+ $ this ->eventDispatcher ->dispatch (Neo4jClientEvents::NEO4J_ON_FAILURE , $ event );
139+ if ($ event ->shouldThrowException ()) {
140+ throw $ exception ;
141+ }
142+ return null ;
143+ }
113144
114145 return $ results ;
115146 }
0 commit comments