定义异常类
app/Exception/HttpException.php
<?php
/**
* ----------------------------------------------------------
* date: 2020/7/22 13:59
* ----------------------------------------------------------
* author: Raoxiaoya
* ----------------------------------------------------------
* describe:
* ----------------------------------------------------------
*/
namespace App\Exception;
use App\Constants\ErrorCode;
use Hyperf\Server\Exception\ServerException;
use Throwable;
class HttpException extends ServerException
{
public function __construct(int $code = 0, string $message = null, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
使用
throw new HttpException(4000, '该作品不存在');