Socket
Socket
Sign inDemoInstall

logged-errors

Package Overview
Dependencies
6
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    logged-errors

restify component (errors), extracted from "restify" with additional chainable features


Version published
Weekly downloads
6
increased by200%
Maintainers
1
Install size
208 kB
Created
Weekly downloads
 

Readme

Source

logged-errors

This module is a simple fork of the restify-errors with some chainable features:

  • it can log the error using an external logger (e.g. winston)
  • it can show the error stack in the body of the error
  • it can format the log output
  • it works both in Node and browser

Installation

Install logged-errors as usual:

$ npm install --save logged-errors

For browser environment add logged-error.js file in build folder.

Example

// see the examples folder

// dependencies
var LoggedErrors = require('logged-errors');

// add the stack to the body of the error
throw new LoggedErrors.NotFoundError('some error').withStack().log();

// the following statements are equivalent
throw new LoggedErrors.NotFoundError('some error').withStack().toArray().log();
throw new LoggedErrors.NotFoundError('some error').withStack(true).log();

// set a new format and a custom logger (default is console)
LoggedErrors.set({
    format: function (e) {
        return 'error occurred: ' + e.message;
    },
    logger: require('winston')
});

// change on the fly the content used for the log using the defult format
// use body (default)
throw new LoggedErrors.NotFoundError('some error').log();
// use message (set mode !== 'body')
throw new LoggedErrors.NotFoundError('some error').log('msg');

// compose a message for the error
throw new LoggedErrors.NotFoundError('some error with %s and %s', 'first parameter', 'second parameter').log();

For other information please refer to restify documentation.

Keywords

FAQs

Last updated on 08 Jun 2014

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc