Merge pull request #4 from ilovintit/main

验证器异常捕捉按规定格式返回响应
This commit is contained in:
Easy 2021-12-27 23:01:17 +08:00 committed by GitHub
commit f45975f051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,8 @@ class Handler extends ExceptionHandler
$this->reportable(function (Throwable $e) {
//
});
$this->renderable(function (ValidationException $e) {
return send_error($e->errors()[array_key_first($e->errors())][0] ?? $e->getMessage(), ErrorCode('ARGS'));
});
}
}