Skip to content

Commit

Permalink
Better error message when trying to connect to http port
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed May 16, 2016
1 parent d03dec4 commit d4cef21
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ trap finish EXIT

npm install
npm run start-neo4j
sleep 2
npm test
7 changes: 5 additions & 2 deletions src/v1/internal/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,11 @@ class Connection {
if( buf.hasRemaining() ) {
self._dechunker.write(buf.readSlice( buf.remaining() ));
}

} else {
} else if (proposed == 1213486160) {//server responded 1213486160 == 0x48545450 == "HTTP"
self._handleFatalError(newError("Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
"(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)"));
}
else {
self._handleFatalError(newError("Unknown Bolt protocol version: " + proposed));
}
};
Expand Down
21 changes: 21 additions & 0 deletions test/internal/connector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,25 @@ describe('connector', function() {
done();
});

it('should provide error message when connecting to http-port', function(done) {
// Given
var conn = connect("bolt://localhost:7474");

// When
conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}, {
onCompleted: function( msg ) {
},
onError: function(err) {
//only node gets the pretty error message
if( require('../../lib/v1/internal/ch-node.js').available ) {
expect(err.message).toBe("Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
"(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)");
}
done();
}
});
conn.sync();

});

});
14 changes: 7 additions & 7 deletions test/v1/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out[0]).toBe("There were 1 the ones created.");
done();
}, 500)
}, 1000)
});

it('should be able to iterate results', function(done) {
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out[0]).toBe("Sword in the stone");
done();
}, 500);
}, 1000);
});

it('should be able to access records', function(done) {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out[0].length).toBe(3);
done();
}, 500)
}, 1000)
});

it('should be able to retain for later processing', function(done) {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out[0]).toBe("Lancelot is a knight of Camelot");
done();
}, 500);
}, 1000);
});

it('should be able to do nested queries', function(done) {
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out[0]).toBe("Count is 1");
done();
}, 500);
}, 1000);
});

it('should be able to handle cypher error', function(done) {
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('examples', function() {
setTimeout(function() {
expect(out.length).toBe(1);
done();
}, 500);
}, 1000);
});

it('should be able to see notifications', function(done) {
Expand All @@ -315,7 +315,7 @@ describe('examples', function() {
setTimeout(function () {
expect(out[0]).toBe("Neo.ClientNotification.Statement.CartesianProductWarning");
done();
}, 500);
}, 1000);
});

it('should document committing a transaction', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/v1/tck/steps/tlssteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function () {
callback();
});

this.Then(/^sessions should simply work$/, function (callback) {
this.Then(/^sessions should simply work$/, {timeout: 60 * 1000}, function (callback) {
var session = this.driver1.session();
session.run("RETURN 1").then(function (result) {
session.close();
Expand Down

0 comments on commit d4cef21

Please sign in to comment.