17
17
use Bolt \error \MessageException ;
18
18
use Ds \Vector ;
19
19
use Exception ;
20
+ use Laudis \Neo4j \Common \TransactionHelper ;
20
21
use Laudis \Neo4j \Contracts \FormatterInterface ;
21
22
use Laudis \Neo4j \Contracts \UnmanagedTransactionInterface ;
22
23
use Laudis \Neo4j \Databags \Neo4jError ;
@@ -62,7 +63,8 @@ public function commit(iterable $statements = []): CypherList
62
63
$ this ->bolt ->commit ();
63
64
$ this ->finished = true ;
64
65
} catch (Exception $ e ) {
65
- throw new Neo4jException (new Vector ([new Neo4jError ('' , $ e ->getMessage ())]), $ e );
66
+ $ code = TransactionHelper::extractCode ($ e );
67
+ throw new Neo4jException (new Vector ([new Neo4jError ($ code ?? '' , $ e ->getMessage ())]), $ e );
66
68
}
67
69
68
70
return $ tbr ;
@@ -78,7 +80,8 @@ public function rollback(): void
78
80
$ this ->bolt ->rollback ();
79
81
$ this ->finished = true ;
80
82
} catch (Exception $ e ) {
81
- throw new Neo4jException (new Vector ([new Neo4jError ('' , $ e ->getMessage ())]), $ e );
83
+ $ code = TransactionHelper::extractCode ($ e ) ?? '' ;
84
+ throw new Neo4jException (new Vector ([new Neo4jError ($ code , $ e ->getMessage ())]), $ e );
82
85
}
83
86
}
84
87
@@ -115,7 +118,8 @@ public function runStatements(iterable $statements): CypherList
115
118
$ results = $ this ->bolt ->pullAll ();
116
119
} catch (Throwable $ e ) {
117
120
if ($ e instanceof MessageException) {
118
- throw new Neo4jException (new Vector ([new Neo4jError ('' , $ e ->getMessage ())]), $ e );
121
+ $ code = TransactionHelper::extractCode ($ e ) ?? '' ;
122
+ throw new Neo4jException (new Vector ([new Neo4jError ($ code , $ e ->getMessage ())]), $ e );
119
123
}
120
124
throw $ e ;
121
125
}
0 commit comments