Skip to content

Commit 38611ae

Browse files
author
DvirDukhan
authored
Merge pull request #23 from RedisGraph/runtime-exceptions
added support for server exceptions.
2 parents 2953fa2 + ff3e848 commit 38611ae

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/resultSet.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const Statistics = require("./statistics"),
22
Record = require("./record");
3-
Node = require("./node");
4-
Edge = require("./edge");
3+
Node = require("./node");
4+
Edge = require("./edge");
5+
ReplyError = require("redis").ReplyError
56

67
const ResultSetColumnTypes = {
78
COLUMN_UNKNOWN: 0,
@@ -40,9 +41,11 @@ class ResultSet {
4041
* The last list is the statistics list.
4142
*/
4243
async parseResponse(resp) {
43-
if (Array.isArray(resp)) {
44-
if (resp.length < 3) {
45-
this._statistics = new Statistics(resp[resp.length - 1]);
44+
if(Array.isArray(resp)) {
45+
let statistics = resp[resp.length - 1];
46+
if(statistics instanceof ReplyError) throw statistics;
47+
if(resp.length < 3) {
48+
this._statistics = new Statistics(statistics);
4649
} else {
4750
await this.parseResults(resp);
4851
this._resultsCount = this._results.length;

test/redisGraphAPITest.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,29 @@ describe('RedisGraphAPI Test', function () {
263263
console.log(error);
264264
})
265265
})
266+
267+
it('testCompileTimeException', (done) => {
268+
api.query("CREATE ()").then(response => {
269+
api.query("RETURN toUpper(5)").then(response => assert(false)).catch (err => {
270+
assert(err instanceof redis.ReplyError);
271+
assert.equal(err.message, "Type mismatch: expected String but was Integer");
272+
done();
273+
})
274+
}).catch(error => {
275+
console.log(error);
276+
})
277+
})
278+
279+
it('testRuntimeException', (done) => {
280+
api.query("CREATE ({val:5})").then(response => {
281+
api.query("MATCH (n) RETURN toUpper(n.val)").then(response => assert(false)).catch (err => {
282+
assert(err instanceof redis.ReplyError);
283+
assert.equal(err.message, "Type mismatch: expected String but was Integer");
284+
done();
285+
})
286+
}).catch(error => {
287+
console.log(error);
288+
})
289+
})
290+
266291
});

0 commit comments

Comments
 (0)