兼容修改
This commit is contained in:
53
support/MyExceptionHandle.php
Normal file
53
support/MyExceptionHandle.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
namespace support;
|
||||
|
||||
use app\exception\SysException;
|
||||
use Throwable;
|
||||
use Webman\Exception\ExceptionHandler;
|
||||
use Webman\Exception\ExceptionHandlerInterface;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Exception\BusinessException;
|
||||
|
||||
/**
|
||||
* Class Handler
|
||||
* @package support\exception
|
||||
*/
|
||||
class MyExceptionHandle extends ExceptionHandler implements ExceptionHandlerInterface
|
||||
{
|
||||
public $dontReport = [
|
||||
BusinessException::class,
|
||||
];
|
||||
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
Log::error("捕获到全局异常,异常信息: ".$exception->getMessage());
|
||||
Log::error($exception->getTraceAsString());
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
public function render(Request $request, Throwable $exception): Response
|
||||
{
|
||||
return json( [
|
||||
'code' => -1,
|
||||
'message' => $exception->getMessage(),
|
||||
'time' => time(),
|
||||
'data' => [],
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user