1.0.5 • Published 8 years ago

fuu v1.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

fuu

Fuu is a simple module made for learning purposes and for a API, please do not expect something fancy.

Installation

npm install fuu

Usage

Fuu is built to use with express framework, first you have to initialize the custom errors and use the prebuilt handlers.

The field message and status are not required, ou can either pass an array or just a single error.

var fuu = require('fuu');

fuu.add([
    { code: 1, message: 'Custom error' },
    { code: 2, message: 'Auth error', status: 401 }    
]);

fuu.add({ code: 3, message: 'Nothing was found on database', status: 404 })

if(app.get('env') === 'development')
    app.use(fuu.handlers.expressDev);

app.use(fuu.handlers.expressProd);

Error example

You can send the default error together, fuu will get the error by its code and set the message and status if defined, if not, will fallback to the default ones.

Fuu handlers will send a JSON response, in the future I'm planning to make it able to render and send a view as response.

app.get('/', function(req, res, next){
    getSomethingFromDb(function(err, data) {
        if(err)
            next({ code: 1, error:  err });
        else if(data.length == 0)
            next({ code: 3 });
        else
            res.send(data):
    });
};
1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.0-reserved

8 years ago