2.0.0 • Published 4 years ago

@sealsystems/assert-mongo-error v2.0.0

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

@sealsystems/assert-mongo-error

CircleCI AppVeyor

Test for a servere mongodb error and handle it by exiting the process, throwing a new generated @sealsystems/error error object or just ignore the error.

Default list of severe mongodb error codes to exit:

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

Installation

$ npm install @sealsystems/assert-mongo-error

Quick start

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

const assertMongoError = require('@sealsystems/assert-mongo-error');

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

Assert Error

Test for a servere mongodb error. The function has three outcomes:

  • In case of a severe mongodb error exit the process
  • Without any of the optional parameters the mongodb error is ignored and the function returns.
  • If at least an error message is given as second parameter it throws a new created error of type @sealsystems/error. The original mongodb error is chained to the new error.
assertMongoError.assert(error, message, code, metadata);

Parameters:

error      object  mandatory  The error object to test
message    string  optional   Message used for creating a new error object
code       number  optional   Code used for creating a new error object
metadata   object  optional   Metadata used for creating a new error object

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('@sealsystems/assert-mongo-error');

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

Running the build

To build this module use roboter.

$ bot
2.0.0

4 years ago

1.3.9

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.8

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.2

7 years ago