import { bizlive } from "tencentcloud-sdk-nodejs";
import { ERRORCODEENUM } from "../config/enum/errorEnum";

/**
 * 中间件 错误返回
 * @param err 
 * @param req 
 * @param res 
 * @param next 
 */
export function httpErrorHandler(err, req, res, next) {
    // console.log("in httpErrorHandler");
    console.log(err);
    //todo 自定义错误编码
    if (err) {
        if ( ERRORCODEENUM[err.message] ) {
            res.success({success:false, msg:err.message, code:ERRORCODEENUM[err.message]});
            next();
        }
        else {
            console.log(req.ip, err.message);
            res.send({success:false, msg:err.message, code:500});
            // res.success({success:false, msg:err.message, code:500});
            next();
        }
    }
} 