This commit is contained in:
2021-09-10 10:53:54 +08:00
parent 1db221c771
commit abb9508c36
2 changed files with 8 additions and 6 deletions
+7 -6
View File
@@ -4,9 +4,11 @@ namespace Server;
use Server\Constrict\Response;
use Server\Constrict\Response as CResponse;
use Server\Message\Stream;
use Protocol\Message\Response as CResponse;
use Throwable;
use Protocol\Message\Stream;
use Server\Constrict\ResponseInterface;
/**
*
@@ -17,20 +19,19 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
/**
* @param Throwable $exception
* @param CResponse $response
* @param Response $response
* @return ResponseInterface
* @throws \Exception
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
{
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))
->withContentType(Message\Response::CONTENT_TYPE_HTML)
->withContentType(CResponse::CONTENT_TYPE_HTML)
->withStatus(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withContentType(Message\Response::CONTENT_TYPE_HTML)
->withContentType(CResponse::CONTENT_TYPE_HTML)
->withStatus($code);
}
@@ -4,6 +4,7 @@ namespace Server;
use Server\Constrict\Response;
use Throwable;
use Server\Constrict\ResponseInterface;
/**
*