0.0.9 • Published 8 years ago

common-rest-errors v0.0.9

Weekly downloads
5
License
ISC
Repository
github
Last release
8 years ago

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

8 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago