基础数据-校区服务
This commit is contained in:
45
app/Exception/BusinessException.php
Normal file
45
app/Exception/BusinessException.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception;
|
||||
|
||||
use Hyperf\Server\Exception\ServerException;
|
||||
use Throwable;
|
||||
|
||||
class BusinessException extends ServerException
|
||||
{
|
||||
/**
|
||||
* 业务异常.
|
||||
* @param int $code 错误码
|
||||
* @param string $message 错误消息
|
||||
*/
|
||||
public function __construct(int $code = 500, string $message = '', ?Throwable $previous = null)
|
||||
{
|
||||
if (empty($message)) {
|
||||
$message = $this->getDefaultMessage($code);
|
||||
}
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认错误消息.
|
||||
*/
|
||||
private function getDefaultMessage(int $code): string
|
||||
{
|
||||
$messages = [
|
||||
400 => '请求参数错误',
|
||||
401 => '未授权',
|
||||
403 => '禁止访问',
|
||||
404 => '资源不存在',
|
||||
500 => '服务器内部错误',
|
||||
10001 => '校区不存在',
|
||||
10002 => '校区已存在',
|
||||
10003 => '父级校区不存在',
|
||||
10004 => '层级参数错误',
|
||||
];
|
||||
|
||||
return $messages[$code] ?? '业务处理失败';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user