1.2.1 • Published 12 years ago

error-manager v1.2.1

Weekly downloads
1
License
-
Repository
-
Last release
12 years ago

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
1.2.1

12 years ago

1.1.1

12 years ago

1.1.0

12 years ago

1.0.0

12 years ago