Skip to content

Commit

Permalink
Added warn logs when throw BadRequestHttpException.
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Nov 1, 2023
1 parent 375ef09 commit ccda01c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Kernel/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
namespace App\Kernel\Http;

use Hyperf\Context\ResponseContext;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\HttpMessage\Cookie\Cookie;
use Hyperf\HttpMessage\Exception\BadRequestHttpException;
use Hyperf\HttpMessage\Exception\HttpException;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\Contract\ResponseInterface;
Expand Down Expand Up @@ -62,6 +64,10 @@ public function cookie(Cookie $cookie)

public function handleException(HttpException $throwable): ResponsePlusInterface
{
if ($throwable instanceof BadRequestHttpException) {
di()->get(StdoutLoggerInterface::class)->warning('body: ' . $throwable->getRequest()?->getBody() . ' ' . $throwable);
}

return $this->response()
->addHeader('Server', 'Hyperf')
->setStatus($throwable->getStatusCode())
Expand Down

0 comments on commit ccda01c

Please sign in to comment.