Skip to content

Commit 3bda7e1

Browse files
committed
Fixed errors in Session to use Neo4jError properly
1 parent 7791c38 commit 3bda7e1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/v1/session.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import StreamObserver from './internal/stream-observer';
2121
import Result from './result';
2222
import Transaction from './transaction';
23+
import {newError} from "./error";
2324

2425
/**
2526
* A Session instance is used for handling the connection and
@@ -58,8 +59,9 @@ class Session {
5859
this._conn.pullAll(streamObserver);
5960
this._conn.sync();
6061
} else {
61-
streamObserver.onError({error: "Please close the currently open transaction object before running " +
62-
"more statements/transactions in the current session." });
62+
streamObserver.onError(newError("Statements cannot be run directly on a "
63+
+ "session with an open transaction; either run from within the "
64+
+ "transaction or use a different session."));
6365
}
6466
return new Result( streamObserver, statement, parameters );
6567
}
@@ -74,7 +76,9 @@ class Session {
7476
*/
7577
beginTransaction() {
7678
if (this._hasTx) {
77-
throw new newError("Cannot have multiple transactions open for the session. Use multiple sessions or close the transaction before opening a new one.")
79+
throw new newError("You cannot begin a transaction on a session with an "
80+
+ "open transaction; either run from within the transaction or use a "
81+
+ "different session.")
7882
}
7983

8084
this._hasTx = true;

test/v1/session.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ describe('session', function() {
234234
//Then
235235
session.run("RETURN 42")
236236
.catch(function (error) {
237-
expect(error.error).toBe("Please close the currently open transaction object before running " +
238-
"more statements/transactions in the current session." );
237+
expect(error.message).toBe("Statements cannot be run directly on a "
238+
+ "session with an open transaction; either run from within the "
239+
+ "transaction or use a different session." );
239240
done();
240241
})
241242
});

0 commit comments

Comments
 (0)