You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

51 lines
1.2 KiB

<?php
declare(strict_types=1);
/**
* BusinessException.php
* Created by PhpStorm.
* Date: 2026/10/17
* Time: 09:40
* Author: qian.guo
* E-mail: yiyezhiqiutel@gmail.com
*/
namespace app;
use RuntimeException;
use Throwable;
/**
* 业务异常
* 设计说明:
* - 只用于「不可预期之外的失败」:微信接口异常、凭证失效、评分策略配置错误
* 可预期的业务校验(存在性/状态/权限/名额/截止)按规范写在控制器里直接 return json(400)
* - 携带 err_code,由 ExceptionHandle 放进 data.err_code,前端优先用它分支
* 若只能匹配中文 msg 来分支,改一次文案就会静默失效
*/
class BusinessException extends RuntimeException
{
// 细分业务码,见 config/code.php 的 err 段
protected $err_code;
public function __construct($err_code, $message = '', ?Throwable $previous = null)
{
$this->err_code = $err_code;
if ($message === '') {
$message = '操作失败';
}
parent::__construct($message, intval($err_code), $previous);
}
/**
* 读取细分业务码
* getErrCode
* @return int
*/
public function getErrCode()
{
return $this->err_code;
}
}