Files
kiri-core/http-server/ExceptionHandlerDispatcher.php
T
as2252258@163.com 30dae81e7e 111
2021-08-28 01:21:23 +08:00

37 lines
915 B
PHP

<?php
namespace Server;
use Server\Constrict\Response;
use Server\Constrict\Response as CResponse;
use Server\Message\Stream;
use Throwable;
/**
*
*/
class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
{
/**
* @param Throwable $exception
* @param CResponse $response
* @return ResponseInterface
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
{
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))
->withHeader('Content-Type', 'text/html')
->withStatus(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withHeader('Content-Type', 'text/html')
->withStatus($code);
}
}