Bucket ops can throw plain Error without code


#1

I was hoping to catch all connection errors (and return 503 as appropriate) whenever error.code was one of the appropriate constants, such as errors.networkError, errors.connectError, etc. However, I found that if CB server is down, the bucket operations raise an error with a message but no code:

message: cannot perform operations on a shutdown bucket

This is due to bucket.js
throw new Error('cannot perform operations on a shutdown bucket');

Was this done intentionally?
Any chance this will be changed to provide a code?


#2

Hey @twinkle,
One solution would be to watch for the error event being emitted by the bucket to get the real reason for the bucket not connecting. I have included an example below:

...
var bucket = cluster.openBucket('default');
bucket.on('error', function(err) {
  console.log(err, err.code);
});

Cheers, Brett