Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
/ fuu Public archive

Simple custom error handling module for Express.JS

Notifications You must be signed in to change notification settings

euljr/fuu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

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):
    });
};

About

Simple custom error handling module for Express.JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published