Handler.php 2.1 KB

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