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.
 
 

45 lines
1.1 KiB

<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Exception;
use App\Commons\Log;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use Hyperf\Server\Exception\ServerException;
use Throwable;
use Hyperf\Di\Annotation\Inject;
class ErrorCodeException extends ServerException
{
/**
* @Inject
* @var Log
*/
protected $log;
public function __construct(int $code = 0, string $message = null, $logData=[], Throwable $previous = null)
{
if (!empty($logData)) {
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['logData' => json_encode($logData)]);
}
if (is_null($message)) {
$message = ErrorCode::getMessage($code);
} else {
$message = ErrorCode::getMessage($code) . '_' . $message;
}
parent::__construct($message, $code, $previous);
}
}