Laravel自定义错误异常类代码分享,希望对你有所帮助
public function render($request, Exception $exception) { if ($exception instanceof CustomException) { // 如果是自定义的异常 $this->code = $exception->code; $this->message = $exception->message; $result = [ 'code' => $this->code, 'msg' => $this->message, ]; //记录日期 Log::error($exception->message); if($request->ajax()){ return response()->json($result)->setEncodingOptions(JSON_UNESCAPED_UNICODE); }else{ $params = [ 'msg' => $this->message, 'wait' => 3, 'url' => 'javascript:history.back(-1);', ]; return response()->view('common.error', $params, 500); } } return parent::render($request, $exception); }