@@ -52,15 +52,6 @@ public function report(Exception $exception)
5252 */
5353 public function render ($ request , Exception $ exception )
5454 {
55- if ($ exception instanceof NotFoundHttpException){
56- return $ this ->renderNotFoundException ($ exception );
57- }
58- if ($ exception instanceof ModelNotFoundException) {
59- return $ this ->renderModelNotFoundException ($ exception );
60- }
61- if ($ exception instanceof AccessDeniedHttpException) {
62- return $ this ->renderAccessDeniedException ($ exception );
63- }
6455 return parent ::render ($ request , $ exception );
6556 }
6657
@@ -73,72 +64,11 @@ public function render($request, Exception $exception)
7364 */
7465 protected function unauthenticated ($ request , AuthenticationException $ exception )
7566 {
67+
7668 if ($ request ->expectsJson ()) {
7769 return response ()->json (['message ' => 'Unauthenticated. ' ], 401 );
7870 }
7971
8072 return redirect ()->guest ('login ' );
8173 }
82-
83- /**
84- * Create a response object from the given validation exception.
85- *
86- * @param \Illuminate\Validation\ValidationException $e
87- * @param \Illuminate\Http\Request $request
88- * @return \Symfony\Component\HttpFoundation\Response
89- */
90- protected function convertValidationExceptionToResponse (ValidationException $ e , $ request )
91- {
92- if ($ e ->response ) {
93- return $ e ->response ;
94- }
95-
96- $ errors = $ e ->validator ->errors ()->getMessages ();
97-
98- if ($ request ->expectsJson ()) {
99- return response ()->json ([
100- 'message ' => 'Validation error ' ,
101- 'errors ' => $ errors
102- ], 422 );
103- }
104-
105- return redirect ()->back ()->withInput (
106- $ request ->input ()
107- )->withErrors ($ errors );
108- }
109-
110- /**
111- * @return \Illuminate\Http\JsonResponse
112- */
113- protected function renderNotFoundException ($ e )
114- {
115- if (request ()->expectsJson ()){
116- return response ()->json (['message ' => 'Not Found ' ], 404 );
117- }
118- return $ this ->renderHttpException ($ e );
119- }
120-
121- /**
122- * @param $e
123- * @return \Illuminate\Http\JsonResponse
124- */
125- protected function renderModelNotFoundException ($ e )
126- {
127- if (request ()->expectsJson ()){
128- return response ()->json (['message ' => 'Not Found ' ], 404 );
129- }
130- throw new NotFoundHttpException ();
131- }
132-
133- /**
134- * @param $e
135- * @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
136- */
137- protected function renderAccessDeniedException ($ e )
138- {
139- if (request ()->expectsJson ()){
140- return response ()->json (['message ' => 'Forbidden ' ], 403 );
141- }
142- return $ this ->renderHttpException ($ e );
143- }
14474}
0 commit comments