Handler.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
  5. use Illuminate\Database\QueryException;
  6. use Throwable;
  7. class Handler extends ExceptionHandler
  8. {
  9. /**
  10. * A list of the exception types that are not reported.
  11. *
  12. * @var array<int, class-string<Throwable>>
  13. */
  14. protected $dontReport = [
  15. //
  16. ];
  17. /**
  18. * A list of the inputs that are never flashed for validation exceptions.
  19. *
  20. * @var array<int, string>
  21. */
  22. protected $dontFlash = [
  23. 'current_password',
  24. 'password',
  25. 'password_confirmation',
  26. ];
  27. /**
  28. * Register the exception handling callbacks for the application.
  29. *
  30. * @return void
  31. */
  32. public function register()
  33. {
  34. $this->reportable(function (Throwable $e) {
  35. //
  36. });
  37. $this->renderable(function (MethodNotAllowedHttpException $e, $request){
  38. $respuesta = json_encode([
  39. "error" => true,
  40. "msg" => "ERR_GLB_USU000: Método no soportado.",
  41. "response" => []
  42. ]);
  43. return response($respuesta, 405)->header('Content-Type', 'application/json');
  44. });
  45. $this->renderable(function (QueryException $e, $request){
  46. $respuesta = json_encode([
  47. "error" => true,
  48. "msg" => "ERR_GLB_USU000: No se pudo establecer una conexión con la base de datos.",
  49. "response" => []
  50. ]);
  51. return response($respuesta, 500)->header('Content-Type', 'application/json');
  52. });
  53. }
  54. }