File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 44
55use Exception ;
66use Illuminate \Auth \AuthenticationException ;
7+ use Symfony \Component \HttpKernel \Exception \HttpException ;
78use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
89
910class Handler extends ExceptionHandler
@@ -44,9 +45,27 @@ public function report(Exception $exception)
4445 */
4546 public function render ($ request , Exception $ exception )
4647 {
48+ if ($ request ->expectsJson () && $ exception instanceof HttpException) {
49+ return $ this ->handleExceptionJsonResponse ($ exception );
50+ }
51+
4752 return parent ::render ($ request , $ exception );
4853 }
4954
55+ /**
56+ * Handle the JSON response for the HTTP exceptions.
57+ *
58+ * @param \Exception $exception
59+ *
60+ * @return \Illuminate\Http\Response
61+ */
62+ protected function handleExceptionJsonResponse (Exception $ exception )
63+ {
64+ return response ()->json ([
65+ 'messages ' => [$ exception ->getMessage ()],
66+ ], $ exception ->getStatusCode ());
67+ }
68+
5069 /**
5170 * Convert an authentication exception into an unauthenticated response.
5271 *
You can’t perform that action at this time.
0 commit comments