Browse Source

tweak default handler

Taylor Otwell 6 years ago
parent
commit
c2e3cb9065
1 changed files with 18 additions and 13 deletions
  1. 18 13
      app/Exceptions/Handler.php

+ 18 - 13
app/Exceptions/Handler.php

@@ -10,7 +10,7 @@ use Illuminate\Foundation\Exceptions\Handler as 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
      */
@@ -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.
      *
@@ -44,23 +54,18 @@ class Handler extends ExceptionHandler
     }
 
     /**
-     * Convert a validation exception into a response.
+     * Convert a validation exception into a JSON response.
      *
      * @param  \Illuminate\Http\Request  $request
      * @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();
-
-        $errors = $exception->validator->errors()->messages();
-
-        return $request->expectsJson()
-                    ? response()->json(['message' => $message, 'errors' => $errors], 422)
-                    : redirect()->back()->withInput()->withErrors(
-                        $errors, $exception->errorBag
-                    );
+        return response()->json([
+            'message' => $exception->getMessage(),
+            'errors' => $exception->errors(),
+        ], 422);
     }
 
     /**