'app_debug' => false,
'exception_handle' => '\\app\\common\\sysSettingConfig\\Http',
配置了异常接管,
public $httpCode = 200;
public function render(Exception $e){
DebugUtil::log("http error");
$debug_status = config("app_debug");
if($debug_status){
return parent::render($e);
}else{
if ($e instanceof MyException){
DebugUtil::log($e->msg);
return $this->show($e->code, $e->msg, $e->data, 200);
} else {
//若在微信支付回调中发生异常,返回支付失败
$action = request()->action();
if ($action == 'notify'){
echo "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA['']]></return_msg></xml>";
die();
} else {
$errData = Msg::FAIL;
DebugUtil::log($errData);
DebugUtil::log($e->getTraceAsString());
DebugUtil::log($e->getMessage());
return $this->show(1, $errData, '', $this->httpCode);
}
}
}
}
/**
* @param $code
* @param $message
* @param array $data
* @param int $httpCode
* @return \think\response\Json
*/
function show($code, $message ,$data = [] ,$httpCode = 200)
{
$data = [
'code' => $code,
'msg' => $message,
'data' =>$data
];
return json($data, $httpCode);
}
最佳答案
