This commit is contained in:
2023-04-15 23:31:16 +08:00
parent 2d9ac93a7a
commit 41a53200b3
69 changed files with 1678 additions and 749 deletions
+11 -10
View File
@@ -1,12 +1,13 @@
<?php
namespace Kiri\Message;
namespace Kiri\Router\Base;
use Kiri\Message\Constrict\Response;
use Kiri\Message\Constrict\ResponseInterface;
use Kiri\Message\Abstracts\ExceptionHandlerInterface;
use Kiri\Router\ContentType;
use Kiri\Router\Interface\ExceptionHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;
use Kiri\Router\Constrict\Stream;
/**
@@ -18,17 +19,17 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
/**
* @param Throwable $exception
* @param Response $response
* @param object $response
* @return ResponseInterface
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
public function emit(Throwable $exception, object $response): ResponseInterface
{
$response->withContentType(ContentType::HTML);
$response->withContentType(ContentType::HTML)->withBody(new Stream(jTraceEx($exception, null, true)));
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))->withStatus(404);
return $response->withStatus(404);
} else {
return $response->withStatus($exception->getCode() == 0 ? 500 : $exception->getCode());
}
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withStatus($exception->getCode() == 0 ? 500 : $exception->getCode());
}
}