Handler.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. class Handler extends ExceptionHandler
  5. {
  6. /**
  7. * A list of the exception types that are not reported.
  8. *
  9. * @var string[]
  10. */
  11. protected $dontReport = [
  12. //
  13. ];
  14. /**
  15. * A list of the inputs that are never flashed for validation exceptions.
  16. *
  17. * @var string[]
  18. */
  19. protected $dontFlash = [
  20. 'current_password',
  21. 'password',
  22. 'password_confirmation',
  23. ];
  24. /**
  25. * Register the exception handling callbacks for the application.
  26. *
  27. * @return void
  28. */
  29. public function register()
  30. {
  31. $this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $request) {
  32. return response()->json([
  33. 'message' => 'not found'], 404);
  34. });
  35. $this->renderable(function (InvalidOtpParameterException $exception, $request) {
  36. return response()->json([
  37. 'message' => 'invalid OTP parameters',
  38. 'reason' => [$exception->getMessage()]
  39. ], 400);
  40. });
  41. $this->renderable(function (InvalidQrCodeException $exception, $request) {
  42. return response()->json([
  43. 'message' => 'not a valid QR code'], 400);
  44. });
  45. $this->renderable(function (InvalidSecretException $exception, $request) {
  46. return response()->json([
  47. 'message' => 'not a valid base32 encoded secret'], 400);
  48. });
  49. $this->renderable(function (DbEncryptionException $exception, $request) {
  50. return response()->json([
  51. 'message' => $exception->getMessage()], 400);
  52. });
  53. $this->renderable(function (InvalidGoogleAuthMigration $exception, $request) {
  54. return response()->json([
  55. 'message' => __('errors.invalid_google_auth_migration')], 400);
  56. });
  57. $this->renderable(function (UndecipherableException $exception, $request) {
  58. return response()->json([
  59. 'message' => __('errors.cannot_decipher_secret')], 400);
  60. });
  61. $this->renderable(function (UnsupportedOtpTypeException $exception, $request) {
  62. return response()->json([
  63. 'message' => __('errors.unsupported_otp_type')], 400);
  64. });
  65. $this->renderable(function (\Illuminate\Auth\AuthenticationException $exception, $request) {
  66. if ($exception->guards() === ['reverse-proxy-guard']) {
  67. return response()->json([
  68. 'message' => $exception->getMessage()], 407);
  69. }
  70. else {
  71. return response()->json([
  72. 'message' => $exception->getMessage()], 401);
  73. }
  74. });
  75. }
  76. }