mirror of
https://github.com/easychen/pushdeer.git
synced 2025-01-09 22:45:37 +08:00
验证器异常捕捉按规定格式返回响应
This commit is contained in:
parent
30b5456cc2
commit
473910fc6b
@ -3,6 +3,7 @@
|
|||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
@ -37,5 +38,11 @@ class Handler extends ExceptionHandler
|
|||||||
$this->reportable(function (Throwable $e) {
|
$this->reportable(function (Throwable $e) {
|
||||||
//
|
//
|
||||||
});
|
});
|
||||||
|
$this->renderable(function (ValidationException $e) {
|
||||||
|
return response()->json([
|
||||||
|
'code' => ErrorCode('ARGS'),
|
||||||
|
'error' => $e->errors()[0] ?? $e->getMessage()
|
||||||
|
], $e->status);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user