support/exception/Handler.php
public function render(Request $request, Throwable $exception): Response
{
return new Response(200, ['Content-Type' => 'application/json'], $exception->getMessage());
}
我是定義了一個 HttpResponseException.php , 然后封裝了異常拋出函數(shù)
<?php
namespace support\exception;
class HttpResponseException extends \Exception
{}
support/exception/Handler.php
if ($exception instanceof HttpResponseException) {
// 拋出運行時異常
return new Response(200, ['Content-Type' => 'application/json'], $exception->getMessage());
}
return parent::render($request, $exception);