这是我处理任何错误的代码:
应用\异常\处理程序::类
public function render($request, Exception $e)
{
$fe = \Symfony\Component\Debug\Exception\FlattenException::create($e);
$statusCode = $fe->getStatusCode();
$code = $fe->getCode();
$message = $fe->getMessage();
$errorObj = new \App\LOHDomain\Entities\Error($code, $message);
return response()->json(['data' => null, 'error' => $errorObj], $statusCode);
}
当我将虚假的 WSDL URL 解析到 SoapClient 时,它会引发两个异常
{"data":null,"error":{"code":"0","message":"SOAP-ERROR: Parsing WSDL: Couldn't load from 'asdsd' : failed to load external entity \"asdsd\"\n"}}
{"data":null,"error":{"code":"1","message":"SOAP-ERROR: Parsing WSDL: Couldn't load from 'asdsd' : failed to load external entity \"asdsd\"\n"}}
所以json响应变得无效
在供应商中注释这些代码行时,它会引发一个异常:
Laravel\Lumen\Concerns\RegistersExceptionHandlers 特征
protected function registerErrorHandling()
{
error_reporting(-1);
set_error_handler(function ($level, $message, $file = '', $line = 0) {
if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line);
}
});
set_exception_handler(function ($e) {
$this->handleUncaughtException($e);
});
// register_shutdown_function(function () {
// $this->handleShutdown();
// });
}
那么,问题是什么?以及如何在不编辑供应商的情况下解决它?