mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-01-12 13:44:41 +08:00
Fix handling validation errors
This commit is contained in:
parent
0233e44ccd
commit
ad99714882
@ -62,11 +62,15 @@ class Handler extends ExceptionHandler
|
|||||||
if ($e instanceof ValidationException) {
|
if ($e instanceof ValidationException) {
|
||||||
// Quick fix for returning 422
|
// Quick fix for returning 422
|
||||||
// @see https://prinzeugen.net/custom-responses-of-laravel-validations/
|
// @see https://prinzeugen.net/custom-responses-of-laravel-validations/
|
||||||
$e->status = 200;
|
if ($request->expectsJson()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'errno' => 1,
|
'errno' => 1,
|
||||||
'msg' => array_flatten($e->errors())[0]
|
'msg' => $e->validator->errors()->first()
|
||||||
], 200);
|
]);
|
||||||
|
} else {
|
||||||
|
$request->session()->flash('errors', $e->validator->errors());
|
||||||
|
return redirect()->back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->dontReport as $type) {
|
foreach ($this->dontReport as $type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user