From 473910fc6bea516ff77a4195932f1589ad98ee9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E4=BF=8A=E6=9D=B0?= Date: Mon, 27 Dec 2021 22:06:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=99=A8=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E6=8D=89=E6=8C=89=E8=A7=84=E5=AE=9A=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=BF=94=E5=9B=9E=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/Exceptions/Handler.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/app/Exceptions/Handler.php b/api/app/Exceptions/Handler.php index 8e7fbd1..89610dd 100644 --- a/api/app/Exceptions/Handler.php +++ b/api/app/Exceptions/Handler.php @@ -3,6 +3,7 @@ namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Validation\ValidationException; use Throwable; class Handler extends ExceptionHandler @@ -37,5 +38,11 @@ class Handler extends ExceptionHandler $this->reportable(function (Throwable $e) { // }); + $this->renderable(function (ValidationException $e) { + return response()->json([ + 'code' => ErrorCode('ARGS'), + 'error' => $e->errors()[0] ?? $e->getMessage() + ], $e->status); + }); } } From 61ff24e7239c8953d2b527b5e757383e1ec15202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E4=BF=8A=E6=9D=B0?= Date: Mon, 27 Dec 2021 22:10:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=BF=94=E5=9B=9E=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/Exceptions/Handler.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/api/app/Exceptions/Handler.php b/api/app/Exceptions/Handler.php index 89610dd..efc33bc 100644 --- a/api/app/Exceptions/Handler.php +++ b/api/app/Exceptions/Handler.php @@ -39,10 +39,7 @@ class Handler extends ExceptionHandler // }); $this->renderable(function (ValidationException $e) { - return response()->json([ - 'code' => ErrorCode('ARGS'), - 'error' => $e->errors()[0] ?? $e->getMessage() - ], $e->status); + return send_error($e->errors()[0] ?? $e->getMessage(), ErrorCode('ARGS')); }); } } From 106f65feb164a7174b1c4764df20397e1f3fc273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=A4=E4=BF=8A=E6=9D=B0?= Date: Mon, 27 Dec 2021 22:51:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E8=BF=94=E5=9B=9E=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/Exceptions/Handler.php b/api/app/Exceptions/Handler.php index efc33bc..a18882a 100644 --- a/api/app/Exceptions/Handler.php +++ b/api/app/Exceptions/Handler.php @@ -39,7 +39,7 @@ class Handler extends ExceptionHandler // }); $this->renderable(function (ValidationException $e) { - return send_error($e->errors()[0] ?? $e->getMessage(), ErrorCode('ARGS')); + return send_error($e->errors()[array_key_first($e->errors())][0] ?? $e->getMessage(), ErrorCode('ARGS')); }); } }