|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Exceptions;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
+use App\Services\LogService;
|
|
|
use Exception;
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
@@ -56,18 +57,35 @@ class Handler extends ExceptionHandler
|
|
|
public function render($request, Throwable $exception)
|
|
|
{
|
|
|
try{
|
|
|
- if (method_exists($exception,'getStatusCode')) {
|
|
|
- $code = $exception->getStatusCode();
|
|
|
- Controller::logS('exception',$code,$exception->getTraceAsString().'|| '.$exception->getMessage().' ||'.json_encode($request));
|
|
|
- switch ($code){
|
|
|
- case 419:return response()->view('exception.login');
|
|
|
- case 404:return response()->view('exception.404');
|
|
|
- default: return response()->view('exception.default',compact('code'));
|
|
|
+ if(strpos($exception->getMessage(),'This action is unauthorized')!==false){
|
|
|
+ return response()->view('exception.unauthorized');
|
|
|
}
|
|
|
+ $errMsg=(function()use($exception){
|
|
|
+ return $errMsg=
|
|
|
+ '异常: '
|
|
|
+ .' code:'.$exception->getStatusCode()??''
|
|
|
+ .' message:'.$exception->getMessage()??''
|
|
|
+ .' trace:'.$exception->getTraceAsString()??'';
|
|
|
+ })();
|
|
|
+ if (method_exists($exception,'getStatusCode')) {
|
|
|
+ $code = $exception->getStatusCode();
|
|
|
+ switch ($code){
|
|
|
+ case 419: $view='exception.login';break;
|
|
|
+ case 404:$view='exception.404';break;
|
|
|
+ default: $view='exception.default';break;
|
|
|
+ }
|
|
|
+ return response()->view($view,[
|
|
|
+ 'code'=> $code,
|
|
|
+ 'message'=>$exception->getMessage(),
|
|
|
+ ]);
|
|
|
}
|
|
|
- Controller::logS('exception',class_basename($exception),$exception->getTraceAsString().'|| ||'.json_encode($request));
|
|
|
- }catch (\Exception $e){
|
|
|
|
|
|
+ }catch (\Exception $e){}finally{
|
|
|
+ LogService::log(__METHOD__,__FUNCTION__,
|
|
|
+ $errMsg??''
|
|
|
+ .'请求:'.json_encode($request->all())
|
|
|
+ .'调用堆栈:'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,4))
|
|
|
+ );
|
|
|
}
|
|
|
return parent::render($request, $exception);
|
|
|
}
|