0.0.1 • Published 7 years ago

seal-assert-mongo-error v0.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

seal-assert-mongo-error

If called with a mongodb error of a predefined (severe error) code it throws the error.

Default list of mongodb error codes to throw:

NameCode
InternalError1
HostUnreachable6
HostNotFound7
NetworkTimeout89
SocketException9001
UnknownError8
ProtocolError17
IllegalOpMsgFlag223
UserNotFound11
Unauthorized13
AuthenticationFailed18
InvalidSSLConfiguration140
SSLHandshakeFailed141
OutOfDiskSpace14031

Installation

$ npm install seal-assert-mongo-error

Quick start

First you need to add a reference to seal-assert-mongo-error within your application, then call the assert function in the callback of every mongodb call.

const assertMongoError = require('seal-assert-mongo-error');

yourCollection.find({}, (findError, cursor) => {
  assertMongoError.assert(findError);
  ...
});

Set list of error codes

Use the setCodes function to set a new list of error codes. This needs to be done only once, e.g. at startup. The new list is available instantly throughout the whole node process.

const assertMongoError = require('seal-assert-mongo-error');

assertMongoError.setCodes([1,2,3]);
...
assertMongoError.assert(mongoErrorObject);

Running the build

To build this module use roboter.

$ bot