diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7e21b48b..4515ee00 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -2,6 +2,7 @@ namespace App\Exceptions; +use Illuminate\Support\Arr; use Throwable; use Illuminate\Foundation\Exceptions\RegisterErrorViewPaths; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; @@ -41,6 +42,27 @@ class Handler extends ExceptionHandler } + /** + * Convert the given exception to an array. + * + * @param \Throwable $e + * @return array + */ + protected function convertExceptionToArray(Throwable $e) + { + + return config('app.debug') ? [ + 'message' => $e->getMessage(), + 'exception' => get_class($e), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'trace' => collect($e->getTrace())->map(fn ($trace) => Arr::except($trace, ['args']))->all(), + ] : [ + 'message' => $this->isHttpException($e) ? $e->getMessage() : 'Server Error', + ]; + } + + /** * 自定义错误信息页面, 前台与后台不同, 需要分开定义 */ diff --git a/beike/Shop/Http/Controllers/Account/LoginController.php b/beike/Shop/Http/Controllers/Account/LoginController.php index 71aaff2c..3db54c9f 100644 --- a/beike/Shop/Http/Controllers/Account/LoginController.php +++ b/beike/Shop/Http/Controllers/Account/LoginController.php @@ -12,9 +12,13 @@ namespace Beike\Shop\Http\Controllers\Account; use Beike\Models\Customer; -use Beike\Shop\Http\Controllers\Controller; -use Beike\Shop\Http\Requests\LoginRequest; use Illuminate\Support\Facades\Auth; +use Beike\Shop\Http\Requests\LoginRequest; +use Beike\Shop\Http\Controllers\Controller; +use Illuminate\Validation\UnauthorizedException; +use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class LoginController extends Controller { @@ -29,13 +33,13 @@ class LoginController extends Controller public function store(LoginRequest $request) { if (!auth(Customer::AUTH_GUARD)->attempt($request->only('email', 'password'))) { - throw new \Exception(trans('shop/login.email_or_password_error')); + throw new NotAcceptableHttpException(trans('shop/login.email_or_password_error')); } $customer = current_customer(); if ($customer && $customer->status != 1) { Auth::guard(Customer::AUTH_GUARD)->logout(); - throw new \Exception(trans('shop/login.customer_inactive')); + throw new NotFoundHttpException(trans('shop/login.customer_inactive')); } return json_success(trans('shop/login.login_successfully')); }