Handler.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Exceptions;
  3. use End01here\EasySms\Exceptions\Exception as EndException;
  4. use Exception;
  5. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  6. class Handler extends ExceptionHandler
  7. {
  8. /**
  9. * A list of the exception types that are not reported.
  10. *
  11. * @var array
  12. */
  13. protected $dontReport = [
  14. FrequencyException::class
  15. ];
  16. /**
  17. * A list of the inputs that are never flashed for validation exceptions.
  18. *
  19. * @var array
  20. */
  21. protected $dontFlash = [
  22. 'password',
  23. 'password_confirmation',
  24. ];
  25. /**
  26. * Report or log an exception.
  27. *
  28. * @param \Exception $exception
  29. * @return void
  30. */
  31. public function report(Exception $exception)
  32. {
  33. parent::report($exception);
  34. }
  35. /**
  36. * Render an exception into an HTTP response.
  37. *
  38. * @param \Illuminate\Http\Request $request
  39. * @param \Exception $exception
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function render($request, Exception $exception)
  43. {
  44. if (!env('APP_DEBUG')) {
  45. if ($exception instanceof FrequencyException) {
  46. $result = [
  47. "msg" => __($exception->getMessage()),
  48. "data" => [],
  49. "code" => $exception->getCode()
  50. ];
  51. return response()->json($result);
  52. }elseif ($exception instanceof EndException){
  53. $result = [
  54. "msg" => __($exception->getMessage()),
  55. "data" => [],
  56. "code" => $exception->getCode()
  57. ];
  58. return response()->json($result);
  59. }elseif ($exception instanceof MemberAuthException){
  60. $result = [
  61. "msg" => __('auth.no_login'),
  62. "data" => [],
  63. "code" => 401
  64. ];
  65. return response()->json($result);
  66. }elseif ($exception instanceof ShopAuthException){
  67. $result = [
  68. "msg" =>__('auth.no_login'),
  69. "data" => [],
  70. "code" => 401
  71. ];
  72. return response()->json($result);
  73. } else {
  74. $result = [
  75. "msg" => __('sys.error'),
  76. "data" => [],
  77. "code" => 0
  78. ];
  79. return response()->json($result);
  80. }
  81. }
  82. return parent::render($request, $exception);
  83. }
  84. }