33 lines
759 B
PHP
33 lines
759 B
PHP
<?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);
|
||
}
|
||
} |