$ npm i egg-normal-response-x --save
// {app_root}/config/plugin.js
exports.normalResponse = {
enable: true,
package: 'egg-normal-response-x',
};
// {app_root}/config/config.default.js
exports.normalResponse = {
outSystemError: false, // 是否输出系统错误信息到客户端
systemErrorCode: 500, // 系统错误时返回的HTTP状态码
userErrorCode: 600, // 用户请求错误时返回的HTTP状态码
succeeCode: 200, // 请求成功时返回的HTTP状态码
ignore: ["/*", "*/upload/*", "/assets/*", "/static/*"] // 忽略特定路径的请求,不对这些路径的响应进行处理
};
更多详细信息请参阅 config/config.default.js。
错误抛出示例
throw new UserRequestError("u-token不能为空", "xxx", data);
请在此处提交问题。