This commit is contained in:
2021-08-04 15:39:06 +08:00
parent 9f9d19415d
commit 9589a394eb
3 changed files with 21 additions and 10 deletions
+10 -5
View File
@@ -5,6 +5,7 @@ namespace Server;
use Server\Constrict\Response;
use Server\Constrict\Response as CResponse;
use Throwable;
/**
*
@@ -14,15 +15,19 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
/**
* @param \Throwable $exception
* @param Throwable $exception
* @param CResponse $response
* @return Response
* @return CResponse|\HttpServer\Http\Response
*/
public function emit(\Throwable $exception, Response $response): Response
public function emit(Throwable $exception, Response $response): Response|\HttpServer\Http\Response
{
if ($exception->getCode() == 404) {
return $response->setContent($exception->getMessage())
->setFormat(CResponse::HTML)
->setStatusCode(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
$data = $code == 404 ? $exception->getMessage() : jTraceEx($exception, null, true);
return $response->setContent($data)
return $response->setContent(jTraceEx($exception, null, true))
->setFormat(CResponse::HTML)
->setStatusCode($code);
}
+5 -3
View File
@@ -2,7 +2,9 @@
namespace Server;
use HttpServer\Http\Response as SResponse;
use Server\Constrict\Response;
use Throwable;
/**
*
@@ -12,10 +14,10 @@ interface ExceptionHandlerInterface
/**
* @param \Throwable $exception
* @param Throwable $exception
* @param Response $response
* @return Response
* @return Response|SResponse
*/
public function emit(\Throwable $exception, Response $response): Response;
public function emit(Throwable $exception, Response $response): Response|SResponse;
}
+6 -2
View File
@@ -7,20 +7,19 @@ use Annotation\Annotation;
use HttpServer\Http\Context;
use HttpServer\Http\HttpParams;
use HttpServer\Http\Request;
use HttpServer\Http\Response;
use HttpServer\Route\Router;
use JetBrains\PhpStorm\Pure;
use Snowflake\Abstracts\Config;
use Snowflake\Aop;
use Snowflake\Application;
use Snowflake\Core\ArrayAccess;
use Snowflake\Core\Json;
use Snowflake\Error\Logger;
use Snowflake\Event;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\WebSocket\Server;
use Server\Constrict\Response;
if (!function_exists('make')) {
@@ -55,6 +54,11 @@ if (!function_exists('make')) {
if (!function_exists('workerName')) {
/**
* @param $worker_id
* @return string
*/
function workerName($worker_id)
{
return $worker_id >= Snowflake::app()->getSwoole()->setting['worker_num'] ? 'Task' : 'Worker';