Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sealsystems/assert-mongo-error

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sealsystems/assert-mongo-error

Throws on a servere mongodb error.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
Maintainers
4
Weekly downloads
 
Created
Source

@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

FAQs

Package last updated on 15 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc