tweak default handler
This commit is contained in:
parent
ebc18e3aef
commit
c2e3cb9065
|
@ -10,7 +10,7 @@
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A list of the exception types that should not be reported.
|
* A list of the exception types that are not reported.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,16 @@ class Handler extends ExceptionHandler
|
||||||
//
|
//
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of the inputs that are never flashed for validation exceptions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $dontFlash = [
|
||||||
|
'password',
|
||||||
|
'password_confirmation',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report or log an exception.
|
* Report or log an exception.
|
||||||
*
|
*
|
||||||
|
@ -44,23 +54,18 @@ public function render($request, Exception $exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a validation exception into a response.
|
* Convert a validation exception into a JSON response.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Illuminate\Validation\ValidationException $exception
|
* @param \Illuminate\Validation\ValidationException $exception
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
protected function invalid($request, ValidationException $exception)
|
protected function invalidJson($request, ValidationException $exception)
|
||||||
{
|
{
|
||||||
$message = $exception->getMessage();
|
return response()->json([
|
||||||
|
'message' => $exception->getMessage(),
|
||||||
$errors = $exception->validator->errors()->messages();
|
'errors' => $exception->errors(),
|
||||||
|
], 422);
|
||||||
return $request->expectsJson()
|
|
||||||
? response()->json(['message' => $message, 'errors' => $errors], 422)
|
|
||||||
: redirect()->back()->withInput()->withErrors(
|
|
||||||
$errors, $exception->errorBag
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue