Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    error-managerpublic

    About

    ErrorManager is a very small utility for managing types of Errors in an ExpressJS application.

    This is pretty alpha so design may change as I use tweak it in actual real world usage.

    Example Usage

    It's Coffeescript:

    ErrorManager = require "error-manager"
    
    # ==================== 
    # Create a new types of errors usable in the application
    # ==================== 
    ErrorManager.create "MyCustomError"
    ErrorManager.create "DatabaseBlewUp"
    
    # ==================== 
    # Create a custom express error handling middleware 
    # ==================== 
    app.use (err, req, res, next) ->
        # errors can be checked  using instanceof
        if ! err instanceof ErrorManager.MyCustomError
            return next(err)
    
        res.send "Got MyCustomError"
    
    app.use (err, req, res, next) ->
        # errors can also be checked with a is(), which is injected by ErrorManager
        # into the Error object's prototype
        if err.is(ErrorManager.DatabaseBlewUp) == false
            return next(err)
    
        res.send "Oh snap! The DB blew up."
    
    # ... more error handling middle ware
    

    Installation

    It is meant to be installed as part of your package.json via NPM. Just add a "error-manager": "latest" to the dependencies section.

    Keywords

    none

    install

    npm i error-manager

    Downloadsweekly downloads

    13

    version

    1.2.1

    license

    none

    last publish

    collaborators

    • avatar