New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@firstfleet/fferrorhandler

Package Overview
Dependencies
Maintainers
3
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firstfleet/fferrorhandler

handle errors

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
155
1191.67%
Maintainers
3
Weekly downloads
 
Created
Source

@firstfleet/fferrorhandler

A centralized error handler. Uses a custom error object so we not only get the stack trace but we can also track attributes the tie into papertrails log aggregation. Those attributes we are using are, sender, program, message, severity. We also set a custom attribute called isOperational. This denotes if an error is an operational error or a programmer error.

The error handler also handles all uncaughtException, and unhandledRejection. On uncaughtException if the error is Operational, the process is restarted after the error is logged.

If you update the js docs you can rebuild them by running npm run build-docs

To publish to npm

  • Increment the package version
  • Login by running npm login
  • Make sure you have been added to the firstfleet org
  • run npm run publish

Error Handler

Exports a custom error type AppError. Can be flagged as a programmer error or an operational error. All errors should be capture, when you want to throw an error, import the module

const { AppError } = require('...pathToErrorModule/errorHandler');

Then throw the custom error. The custom error takes in a sender, program, message, severity and a boolean for isOperational

throw new AppError('Invalid Input', 'Describe what happened', true);

There is also a built in error handler. You can import it

const { handleError, errorLevels } = require('...pathToErrorModule/errorHandler');

Then call it when you want to handle an error. Error levels can be imported from the errorType file. The error handler is async so it will finish logging before process.exit calls. Handle error returns a promise so you can handle async errors and compose.

handlerError(sender, program, message, severity, isOperational);
handleError('Node1', 'ffmobileNode2', errorLevels.COMMON, true);

The error handler will transform the error into our custom AppErro type, send it to papertrail, and console log it if the process.ENV !== 'production'

Programmer Error

Programmer errors refer to cases where you have no idea why and sometimes where an error came from – it might be some code that tried to read an undefined value or DB connection pool that leaks memory.

Operational Error

Operational errors refer to situations where you understand what happened and the impact of it – for example, a query to some HTTP service failed due to connection problem.

FAQs

Package last updated on 26 Mar 2019

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