|
|
@@ -0,0 +1,105 @@
|
|
|
+const rCode = require('../map/rcodeMap');
|
|
|
+
|
|
|
+function success(res,data) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.OK,
|
|
|
+ data: data
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function searchSuccess(res, data, total, key, page, limit) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.OK,
|
|
|
+ data: data,
|
|
|
+ total: total,
|
|
|
+ count: data.length,
|
|
|
+ key: key,
|
|
|
+ page: page,
|
|
|
+ limit: limit
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function ServerError(res,code,msg) {
|
|
|
+ res.json({
|
|
|
+ code: code?code:rCode.ServerError,
|
|
|
+ msg: msg
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function paramFail(res,msg) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.NotParam,
|
|
|
+ msg: msg
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function notLogin(res,msg) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.NotLogin,
|
|
|
+ msg: msg
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function notPermission(res,msg) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.NotPermission,
|
|
|
+ msg: msg
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function customError(res,msg) {
|
|
|
+ res.json({
|
|
|
+ code: rCode.CustomError,
|
|
|
+ msg: msg
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function controlError(res,err,msg) {
|
|
|
+ let errorCode,errorMsg;
|
|
|
+ if(msg){ errorMsg = msg }
|
|
|
+ if(err){
|
|
|
+ if(err.eCode){
|
|
|
+ errorCode = err.eCode;
|
|
|
+ }
|
|
|
+ if(!msg && err.eMsg){
|
|
|
+ errorMsg = err.eMsg;
|
|
|
+ }else{
|
|
|
+ errorMsg = err.message;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!errorCode){ errorCode = rCode.ServerError }
|
|
|
+ if(!errorMsg){ errorMsg = 'server error 9999' }
|
|
|
+ switch (errorCode) {
|
|
|
+ case rCode.OK:
|
|
|
+ success(res,errorMsg);
|
|
|
+ break;
|
|
|
+ case rCode.NotParam:
|
|
|
+ paramFail(res,errorMsg);
|
|
|
+ break;
|
|
|
+ case rCode.NotLogin:
|
|
|
+ notLogin(res,errorMsg);
|
|
|
+ break;
|
|
|
+ case rCode.NotPermission:
|
|
|
+ notPermission(res,errorMsg);
|
|
|
+ break;
|
|
|
+ case rCode.CustomError:
|
|
|
+ customError(res,errorMsg);
|
|
|
+ break;
|
|
|
+ case rCode.Timeout:
|
|
|
+ case rCode.NotFound:
|
|
|
+ case rCode.ApiError:
|
|
|
+ case rCode.SaveError:
|
|
|
+ case rCode.DataRepeat:
|
|
|
+ case rCode.ServerError:
|
|
|
+ default:
|
|
|
+ ServerError(res,errorCode,errorMsg);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ success,
|
|
|
+ searchSuccess,
|
|
|
+ ServerError,
|
|
|
+ paramFail,
|
|
|
+ controlError,
|
|
|
+}
|