Handler.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Illuminate\Support\Arr;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. use Throwable;
  7. use Facade\Ignition\Exceptions\ViewException;
  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 \Throwable
  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. if ($exception instanceof ViewException) {
  51. return response([
  52. 'message' => "主题初始化发生错误,请在后台对主题检查或配置后重试。"
  53. ]);
  54. }
  55. return parent::render($request, $exception);
  56. }
  57. protected function convertExceptionToArray(Throwable $e)
  58. {
  59. return config('app.debug') ? [
  60. 'message' => $e->getMessage(),
  61. 'exception' => get_class($e),
  62. 'file' => $e->getFile(),
  63. 'line' => $e->getLine(),
  64. 'trace' => collect($e->getTrace())->map(function ($trace) {
  65. return Arr::except($trace, ['args']);
  66. })->all(),
  67. ] : [
  68. 'message' => $this->isHttpException($e) ? $e->getMessage() : __("Uh-oh, we've had some problems, we're working on it."),
  69. ];
  70. }
  71. }