Skip to content

cloudbeer/common-rest-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

common-rest-errors

Install

npm i common-rest-errors --save

例子

var errors = require("common-rest-errors");

try{
    throw errors.WHAT_REQUIRE("手机号码或者邮箱");
}catch(e){
    console.log(e);
}

说明

错误列表,为了方便抛出的,尚未国际化,目前只有中文。

在程序中,例外的地方只需要抛出例外即可,如:

if (!passport)
    throw error.WHAT_REQUIRE("手机号码或者邮箱");

在全局中处理例外,如在 koajs 中:

app.use(function *(next) {
    try {
        yield next;
    } catch (err) {
        console.log(err);
        this.status = err.status || 500;
        this.body = {errno: err.errno || -1, errText: err.message};
        this.app.emit('error', err, this);
    }
});

About

genneral erros collections, for throw easily.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published