Skip to content
Browse files

[fix] emit error when an unknown layer is used

  • Loading branch information...
1 parent a141373 commit 5f7fe22216525b474cc4360feda3d3b5fad2a56b @AndreasMadsen committed
Showing with 46 additions and 2 deletions.
  1. +6 −0 lib/core/lisenter.js
  2. +9 −1 lib/core/requester.js
  3. +31 −1 test/simple/abstraction.js
View
6 lib/core/lisenter.js
@@ -34,6 +34,12 @@
// get layer collection
var layerCollection = exports.layers[layerName];
+ // check that layer is supported
+ if (layerCollection === undefined) {
+ this.emit('error', new Error('The layer ' + layerName + ' do not exist.'));
+ return;
+ }
+
// create a new messageHandler
var handler = new message.MessageHandler(this, handlers);
View
10 lib/core/requester.js
@@ -28,8 +28,16 @@
Requester.prototype.connect = function (layerName, object) {
var self = this;
- // Create and store layer object
+ // get layer collection
var layerCollection = exports.layers[layerName];
+
+ // check that layer is supported
+ if (layerCollection === undefined) {
+ this.emit('error', new Error('The layer ' + layerName + ' do not exist.'));
+ return;
+ }
+
+ // Create and store layer object
this.layer = new layerCollection.Requester(object);
// keep online state
View
32 test/simple/abstraction.js
@@ -61,6 +61,36 @@ vows.describe('Testing abstraction interface').addBatch({
'the .layers has been filled': function (result) {
assert.isDefined(result);
}
- }
+ },
+
+ 'when requesting an unknown layer' : {
+ 'using requester': {
+ topic: function () {
+ var requester = thintalk();
+ requester.once('error', this.callback.bind(this, null));
+ requester.connect('unknown');
+ },
+
+ 'an error will be emitted': function (error) {
+ assert.equal(error.message, 'The layer unknown do not exist.');
+ }
+ },
+
+ 'using listener': {
+ topic: function () {
+ var listener = thintalk({
+ add: function (a, b) {
+ return a + b;
+ }
+ });
+ listener.once('error', this.callback.bind(this, null));
+ listener.listen('unknown');
+ },
+
+ 'an error will be emitted': function (error) {
+ assert.equal(error.message, 'The layer unknown do not exist.');
+ }
+ }
+ }
}).exportTo(module);

0 comments on commit 5f7fe22

Please sign in to comment.
Something went wrong with that request. Please try again.