Handler.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 (\Illuminate\Auth\AuthenticationException $exception, $request) {
  58. if ($exception->guards() === ['reverse-proxy-guard']) {
  59. return response()->json([
  60. 'message' => $exception->getMessage()], 407);
  61. }
  62. else {
  63. return response()->json([
  64. 'message' => $exception->getMessage()], 401);
  65. }
  66. });
  67. }
  68. }