support/exception/Handler.php
public function render(Request $request, Throwable $exception): Response { return new Response(200, ['Content-Type' => 'application/json'], $exception->getMessage()); }
我是定义了一个 HttpResponseException.php , 然后封装了异常抛出函数
<?php namespace support\exception; class HttpResponseException extends \Exception {}
if ($exception instanceof HttpResponseException) { // 抛出运行时异常 return new Response(200, ['Content-Type' => 'application/json'], $exception->getMessage()); } return parent::render($request, $exception);
support/exception/Handler.php
我是定义了一个 HttpResponseException.php , 然后封装了异常抛出函数
support/exception/Handler.php