Compare commits

...

1 Commits

Author SHA1 Message Date
as2252258 4cbd1fb500 eee 2024-04-24 14:17:09 +08:00
2 changed files with 36 additions and 6 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ class OnRequest implements OnRequestInterface
public DataGrip $dataGrip)
{
$this->responseEmitter = $this->response->emmit;
$exception = \config('request.exception');
$exception = \config('exception.http');
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
$exception = ExceptionHandlerDispatcher::class;
}
+35 -5
View File
@@ -4,7 +4,14 @@ namespace Kiri\Server\Task;
use Kiri;
use Kiri\Router\Base\ExceptionHandlerDispatcher;
use Kiri\Router\DataGrip;
use Kiri\Router\Interface\ExceptionHandlerInterface;
use Kiri\Server\Constant;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Swoole\Server;
/**
@@ -13,6 +20,25 @@ use Swoole\Server;
class Task
{
public ExceptionHandlerInterface $exception;
/**
* @param ContainerInterface $container
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(public ContainerInterface $container)
{
$exception = \config('exception.task');
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
$exception = ExceptionHandlerDispatcher::class;
}
$this->exception = $this->container->get($exception);
}
/**
* @param Server $server
* @return void
@@ -53,12 +79,16 @@ class Task
*/
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
{
$data = json_decode($data, true);
if (is_null($data)) {
return null;
try {
$data = json_decode($data, true);
if (is_null($data)) {
return null;
}
$data[0] = Kiri::getDi()->get($data[0]);
return call_user_func($data, $task_id, $src_worker_id);
} catch (\Throwable $throwable) {
return $this->exception->emit($throwable, response());
}
$data[0] = Kiri::getDi()->get($data[0]);
return call_user_func($data, $task_id, $src_worker_id);
}