first commit

This commit is contained in:
2023-04-15 23:29:27 +08:00
commit 2d9ac93a7a
71 changed files with 4592 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace Kiri\Message;
use Kiri\Message\Constrict\Response;
use Kiri\Message\Constrict\ResponseInterface;
use Kiri\Message\Abstracts\ExceptionHandlerInterface;
use Throwable;
/**
*
*/
class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
{
/**
* @param Throwable $exception
* @param Response $response
* @return ResponseInterface
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
{
$response->withContentType(ContentType::HTML);
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))->withStatus(404);
}
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withStatus($exception->getCode() == 0 ? 500 : $exception->getCode());
}
}