Просмотр файла app/Exceptions/Handler.php

Размер файла: 1.69Kb
  1. <?php
  2.  
  3. namespace App\Exceptions;
  4.  
  5. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  6. use Illuminate\Http\Request;
  7. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  8. use Throwable;
  9.  
  10. class Handler extends ExceptionHandler
  11. {
  12. /**
  13. * A list of the exception types that are not reported.
  14. *
  15. * @var array
  16. */
  17. protected $dontReport = [
  18. //
  19. ];
  20.  
  21. /**
  22. * A list of the inputs that are never flashed for validation exceptions.
  23. *
  24. * @var array
  25. */
  26. protected $dontFlash = [
  27. 'current_password',
  28. 'password',
  29. 'password_confirmation',
  30. ];
  31.  
  32. /**
  33. * Register the exception handling callbacks for the application.
  34. *
  35. * @return void
  36. */
  37. public function register(): void
  38. {
  39. $this->reportable(function (Throwable $exception) {
  40. $statusCode = $this->isHttpException($exception) ? $exception->getStatusCode() : 500;
  41.  
  42. saveErrorLog($statusCode, $exception->getMessage());
  43. });
  44.  
  45. $this->renderable(function (HttpExceptionInterface $exception, Request $request) {
  46. saveErrorLog($exception->getStatusCode(), $exception->getMessage());
  47.  
  48. if ($request->wantsJson()) {
  49. return response()->json([
  50. 'success' => false,
  51. 'error' => $exception->getMessage() ?: __('errors.error'),
  52. ], $exception->getStatusCode());
  53. }
  54.  
  55. if (! view()->exists('errors.' . $exception->getStatusCode())) {
  56. return response()->view('errors.default', compact('exception'));
  57. }
  58.  
  59. return parent::renderHttpException($exception);
  60. });
  61. }
  62. }