thinkphp-wechat/application/common/exception/ServiceException.php
Wenbin.Wang d49c9fde59 代码
2021-12-24 16:40:05 +08:00

33 lines
759 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\exception;
use think\Exception;
class ServiceException extends Exception
{
public $message = '';
public $httpCode = 500;
public $code = 500;
public function __construct($message = '', $httpCode = 500, $code = 500){
$this->message = $message;
$this->httpCode = $httpCode;
$this->code = $code;
$this->render();
}
/**
* 针对swoole配置中app里设置exception_handle始终无效只能先手动把消息设置成固定格式
*/
protected function render()
{
$data = [
'status' => $this->code,
'message' => $this->message,
'data' => [],
];
$this->message = json_encode($data);
}
}