This commit is contained in:
as2252258@163.com
2021-08-28 01:21:23 +08:00
parent e4a583f8dc
commit 30dae81e7e
7 changed files with 83 additions and 90 deletions
+18 -17
View File
@@ -5,6 +5,7 @@ namespace Server;
use Server\Constrict\Response;
use Server\Constrict\Response as CResponse;
use Server\Message\Stream;
use Throwable;
/**
@@ -14,22 +15,22 @@ 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->setContent($exception->getMessage())
->setFormat(CResponse::HTML)
->setStatusCode(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
return $response->setContent(jTraceEx($exception, null, true))
->setFormat(CResponse::HTML)
->setStatusCode($code);
}
/**
* @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);
}
}