This commit is contained in:
2021-09-10 10:57:48 +08:00
parent abb9508c36
commit 79e5907765
2 changed files with 22 additions and 28 deletions
+13 -15
View File
@@ -3,11 +3,10 @@
namespace Server;
use Server\Constrict\Response;
use Protocol\Message\Response as CResponse;
use Throwable;
use Protocol\Message\Stream;
use Server\Constrict\Response;
use Server\Constrict\ResponseInterface;
use Throwable;
/**
@@ -22,17 +21,16 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
* @param Response $response
* @return ResponseInterface
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
{
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))
->withContentType(CResponse::CONTENT_TYPE_HTML)
->withStatus(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withContentType(CResponse::CONTENT_TYPE_HTML)
->withStatus($code);
}
public function emit(Throwable $exception, Response $response): ResponseInterface
{
$response->withContentType('text/html;charset=utf-8');
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))
->withStatus(404);
}
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
return $response->withBody(new Stream(jTraceEx($exception, null, true)))
->withStatus($code);
}
}