error-manager
A simple Error type manager for expressjs apps
Last updated 8 years ago by mostlygeek .
MIT · Original npm · Tarball · package.json
$ cnpm install error-manager 
SYNC missed versions from official npm registry.

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

ErrorManager = require "ErrorManager"

# ==================== 
# 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

Current Tags

  • 1.2.1                                ...           latest (8 years ago)

4 Versions

  • 1.2.1                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 3
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |