Skip to content

Commit 1c82b3d

Browse files
committed
handle key not found error
1 parent 0ac5ae3 commit 1c82b3d

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

lib/client.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Etcd.prototype.get = function (key, options, callback) {
4646
etcd.configData = null;
4747
(function _getParser (next) {
4848
var response;
49-
5049
if (data) {
5150
try {
5251
response = JSON.parse(data);
@@ -55,6 +54,10 @@ Etcd.prototype.get = function (key, options, callback) {
5554
return callback(e);
5655
}
5756

57+
if (response.errorCode) {
58+
return callback(new Error(response));
59+
}
60+
5861
if (etcd.asJSON) {
5962
return next(etcd._parseResponse(response));
6063
}

lib/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ EtcdConfig.prototype.load = function (path, callback) {
5555
etcdConfig.client.get(configPath, {recursive: true}, function (err, config) {
5656

5757
if (err) {
58-
5958
return callback(err);
6059
}
6160

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "etcd-config",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Load and watch config out of etcd",
55
"main": "index.js",
66
"scripts": {

test/index.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ lab.experiment('etcd-config', function() {
7171
done();
7272
});
7373

74+
lab.test('handles etcd connection error', function (done) {
75+
var options = {
76+
connectionString: 'http://127.0.0.1:4002/'
77+
};
78+
var testConfig = new EtcdConfig(options);
79+
testConfig.identify(identify);
80+
testConfig.load(function (err, config) {
81+
Code.expect(err).to.exist();
82+
done();
83+
});
84+
});
85+
86+
lab.test('handles invalid identify function', function (done) {
87+
var options = {
88+
connectionString: 'http://127.0.0.1:4001/'
89+
};
90+
var testConfig = new EtcdConfig(options);
91+
testConfig.identify('eh');
92+
testConfig.load(function (err, config) {
93+
Code.expect(err).to.exist();
94+
done();
95+
});
96+
});
97+
7498
lab.test('returns a valid config', function (done) {
7599
var options = {
76100
connectionString: 'http://127.0.0.1:4001/'
@@ -101,7 +125,7 @@ lab.experiment('etcd-config', function() {
101125
});
102126
});
103127

104-
lab.test('emits changed events', function (done) {
128+
lab.test('emits changed set events', function (done) {
105129
var options = {
106130
connectionString: 'http://127.0.0.1:4001/',
107131
jsonKeys: true

0 commit comments

Comments
 (0)