做网站维护学什么编程语言数字化营销系统
做网站维护学什么编程语言,数字化营销系统,海口网站建设加q.479185700,哈尔滨住房和城乡建设信息网官网Laravel 中的所有异常都由类App\Exceptions\Handler集中处理#xff0c;这个类有两个方法#xff1a;report 和 render。【report 方法】report 方法用于记录异常并将其发送给外部服务。默认情况下#xff0c;report 方法只是将异常传递给异常基类并写入日志进行记录#x…Laravel 中的所有异常都由类App\Exceptions\Handler集中处理这个类有两个方法report 和 render。【report 方法】report 方法用于记录异常并将其发送给外部服务。默认情况下report 方法只是将异常传递给异常基类并写入日志进行记录我们可以在 report 中自定义异常日志记录行为。【dontReport 属性】异常处理器的 $dontReport 属性用于定义不进行记录的异常类型。默认情况下HttpException 和 ModelNotFoundException 异常不会被记录我们可以添加其他需要忽略的异常类型到这个数组。【render 方法】render 方法负责将异常转化为 HTTP 响应。默认情况下异常会传递给 Response 基类生成响应。我们可以 render 方法中进行异常捕获和返回自定义的 HTTP 响应本次捕获主要通过render方法实现并且定义了一些错误等级。具体代码如下namespace App\Exceptions;use Exception;use Illuminate\Database\QueryException;use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;use Symfony\Component\HttpKernel\Exception\HttpException;class Handler extends ExceptionHandler{protected $levels [100 debug,200 info,300 notice,400 notice,500 warning,600 error,700 critical,800 alert,900 emergency,];protected $msg [100 通信成功,200 请求处理成功,300 身份验证失败,400 参数验证失败,500 请求地址/类型错误,600 数据库语句错误,700 服务端出现异常,800 服务超时请重试,900 程序错误请重试,];protected $code 0;/*** A list of the exception types that are not reported.** var array*/protected $dontReport [//];/*** A list of the inputs that are never flashed for validation exceptions.** var array*/protected $dontFlash [password,password_confirmation,];/*** Report or log an exception.** param \Exception $exception* return void*/public function report(Exception $exception){parent::report($exception);}/*** Render an exception into an HTTP response.** param \Illuminate\Http\Request $request* param \Exception $exception* return \Illuminate\Http\Response*/public function render($request, Exception $exception){if ($exception instanceof HttpException) {$this-code 500;}if ($exception instanceof QueryException) {$this-code 600;}if ($exception instanceof \ReflectionException) {$this-code 700;}if ($exception instanceof \RuntimeException) {$this-code 800;}if ($exception instanceof \ErrorException) {$this-code 900;}if($this-code){$result [request $request-input(),data $exception-getMessage(),code $this-code,msg $this-msg[$this-code],];\Illuminate\Support\Facades\Log::log($this-levels[$this-code],Render Data,$result);unset($result[request]);return response()-json($result, 200);}return parent::render($request, $exception);}}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/89103.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!