Handler.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Illuminate\Validation\ValidationException;
  5. use Throwable;
  6. class Handler extends ExceptionHandler
  7. {
  8. /**
  9. * A list of exception types with their corresponding custom log levels.
  10. *
  11. * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
  12. */
  13. protected $levels = [
  14. //
  15. ];
  16. /**
  17. * A list of the exception types that are not reported.
  18. *
  19. * @var array<int, class-string<\Throwable>>
  20. */
  21. protected $dontReport = [
  22. ];
  23. /**
  24. * A list of the inputs that are never flashed to the session on validation exceptions.
  25. *
  26. * @var array<int, string>
  27. */
  28. protected $dontFlash = [
  29. 'current_password',
  30. 'password',
  31. 'password_confirmation',
  32. ];
  33. /**
  34. * Register the exception handling callbacks for the application.
  35. *
  36. * @return void
  37. */
  38. public function register()
  39. {
  40. $this->reportable(function (Throwable $e) {
  41. return response()->json([
  42. "error" => $e->getMessage(),
  43. ], 400);
  44. });
  45. $this->renderable(function (ValidationException $e) {
  46. return response()->json([
  47. "error" =>json_encode($e->errors())
  48. ], 400);
  49. });
  50. }
  51. }