ExceptionHandle.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\ModelNotFoundException;
  14. use think\exception\Handle;
  15. use think\exception\HttpException;
  16. use think\exception\HttpResponseException;
  17. use think\exception\ValidateException;
  18. use think\Response;
  19. use Throwable;
  20. /**
  21. * 应用异常处理类
  22. */
  23. class ExceptionHandle extends Handle
  24. {
  25. /**
  26. * 不需要记录信息(日志)的异常类列表
  27. * @var array
  28. */
  29. protected $ignoreReport = [
  30. HttpException::class,
  31. HttpResponseException::class,
  32. ModelNotFoundException::class,
  33. DataNotFoundException::class,
  34. ValidateException::class,
  35. ];
  36. /**
  37. * 记录异常信息(包括日志或者其它方式记录)
  38. *
  39. * @access public
  40. * @param Throwable $exception
  41. * @return void
  42. */
  43. public function report(Throwable $exception): void
  44. {
  45. // 使用内置的方式记录异常日志
  46. parent::report($exception);
  47. }
  48. /**
  49. * Render an exception into an HTTP response.
  50. *
  51. * @access public
  52. * @param \think\Request $request
  53. * @param Throwable $e
  54. * @return Response
  55. */
  56. public function render($request, Throwable $e): Response
  57. {
  58. // 添加自定义异常处理机制
  59. // 其他错误交给系统处理
  60. return parent::render($request, $e);
  61. }
  62. }