res-msg-fg
v1.0.7
Published
hanlding error
Downloads
7
Readme
res-msg-fg
to simple response
Examples
例子一:
/**
* @param {Object} payload
* @param {Object} payload.code 异常错误码, 必填, 目前只写了我常用的200/400(默认)/401/403/404/500/502/503/504 ,哈哈哈
* @param {Object} payload.message 异常的返回信息,可选
* @param {Object} payload.data 需要对异常添加的备注,可选
*/
const resMsg = require('res-msg-fg');
resMsg({ code: 400, message: 'bad request', data: { code: 23321 } });
// 返回结果
{
success: false,
data: { code: 23321 },
code: 400,
message: 'bad request'
}
例子二:
code为200只返回succesful、 code 、 data
resMsg({ code: 200, message: 'bad request', data: { code: 23321 } });
// 返回结果
{ success: true, code: 200, data: [ { a: 1231 } ] }