import { bizlive } from "tencentcloud-sdk-nodejs";
import { ERRORCODEENUM } from "../config/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 {
            res.success({success:false, msg:err.message, code:500});
            next();
        }
    }
} 