@@ -28,20 +28,8 @@ class Handler extends AppExceptionHandler
2828 */
2929 public function render ($ request , Throwable $ exception )
3030 {
31- $ path = $ this ->isAdminUri () ? 'admin ' : 'front ' ;
32-
33- if ($ path == "front " ) {
34- return redirect ()->route ('admin.session.create ' );
35- }
36-
37- if ($ exception instanceof HttpException) {
38- $ statusCode = in_array ($ exception ->getStatusCode (), [401 , 403 , 404 , 503 ]) ? $ exception ->getStatusCode () : 500 ;
39-
40- return $ this ->response ($ path , $ statusCode );
41- } elseif ($ exception instanceof ModelNotFoundException) {
42- return $ this ->response ($ path , 404 );
43- } elseif ($ exception instanceof PDOException) {
44- return $ this ->response ($ path , 500 );
31+ if (! config ('app.debug ' )) {
32+ return $ this ->renderCustomResponse ($ request , $ exception );
4533 }
4634
4735 return parent ::render ($ request , $ exception );
@@ -68,6 +56,32 @@ private function isAdminUri()
6856 return strpos (Request::path (), 'admin ' ) !== false ? true : false ;
6957 }
7058
59+ /**
60+ * Render custom HTTP response.
61+ *
62+ * @param \Illuminate\Http\Request $request
63+ * @param \Throwable $exception
64+ * @return \Illuminate\Http\Response|null
65+ */
66+ private function renderCustomResponse ($ request , Throwable $ exception )
67+ {
68+ $ path = $ this ->isAdminUri () ? 'admin ' : 'front ' ;
69+
70+ if ($ path == "front " ) {
71+ return redirect ()->route ('admin.session.create ' );
72+ }
73+
74+ if ($ exception instanceof HttpException) {
75+ $ statusCode = in_array ($ exception ->getStatusCode (), [401 , 403 , 404 , 503 ]) ? $ exception ->getStatusCode () : 500 ;
76+
77+ return $ this ->response ($ path , $ statusCode );
78+ } elseif ($ exception instanceof ModelNotFoundException) {
79+ return $ this ->response ($ path , 404 );
80+ } elseif ($ exception instanceof PDOException) {
81+ return $ this ->response ($ path , 500 );
82+ }
83+ }
84+
7185 private function response ($ path , $ statusCode )
7286 {
7387 if (request ()->expectsJson ()) {
0 commit comments