更新异常处理器
parent
e13ca5cf4b
commit
342c5f7c3d
|
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
@ -111,10 +112,16 @@ class Handler extends ExceptionHandler
|
||||||
*/
|
*/
|
||||||
protected function invalidJson($request, ValidationException $exception)
|
protected function invalidJson($request, ValidationException $exception)
|
||||||
{
|
{
|
||||||
|
$errors = $exception->errors();
|
||||||
|
|
||||||
|
if (is_array($firstMessage = Arr::first($errors))) {
|
||||||
|
$firstMessage = Arr::first($firstMessage);
|
||||||
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'code' => 422,
|
'errcode' => 422,
|
||||||
'message' => $exception->getMessage(),
|
'errmsg' => $firstMessage ?: '参数错误',
|
||||||
'errors' => $exception->errors(),
|
'errors' => $errors,
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue