Handler.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Throwable;
  5. use Illuminate\Support\Facades\Log;
  6. use App\Exceptions\Repositories\HOException;
  7. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  8. class Handler extends ExceptionHandler
  9. {
  10. /**
  11. * A list of the exception types that are not reported.
  12. *
  13. * @var array
  14. */
  15. protected $dontReport = [
  16. //
  17. ];
  18. /**
  19. * A list of the inputs that are never flashed for validation exceptions.
  20. *
  21. * @var array
  22. */
  23. protected $dontFlash = [
  24. 'password',
  25. 'password_confirmation',
  26. ];
  27. /**
  28. * Report or log an exception.
  29. *
  30. * @param \Throwable $exception
  31. * @return void
  32. *
  33. * @throws \Exception
  34. */
  35. public function report(Throwable $exception)
  36. {
  37. parent::report($exception);
  38. }
  39. /**
  40. * Render an exception into an HTTP response.
  41. *
  42. * @param \Illuminate\Http\Request $request
  43. * @param \Throwable $exception
  44. * @return \Symfony\Component\HttpFoundation\Response
  45. *
  46. * @throws \Throwable
  47. */
  48. public function render($request, Throwable $exception)
  49. {
  50. // FIXME LILIN 对详细的错误信息,进行记录,但是不返回给前端
  51. if ($exception instanceof HOException) {
  52. $msg = $exception->getMessage();
  53. $code = $exception->getCode();
  54. } elseif ($exception instanceof NotFoundHttpException) {
  55. $msg = 'not found page';
  56. $code = - 404;
  57. } else {
  58. Log::error(parent::render($request, $exception));
  59. $msg = 'Server Bad';
  60. $code = - 500;
  61. }
  62. return response()->horesp($code, null, $msg);
  63. return parent::render($request, $exception);
  64. }
  65. }