@@ -28,20 +28,8 @@ class Handler extends AppExceptionHandler
28
28
*/
29
29
public function render ($ request , Throwable $ exception )
30
30
{
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 );
45
33
}
46
34
47
35
return parent ::render ($ request , $ exception );
@@ -68,6 +56,32 @@ private function isAdminUri()
68
56
return strpos (Request::path (), 'admin ' ) !== false ? true : false ;
69
57
}
70
58
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
+
71
85
private function response ($ path , $ statusCode )
72
86
{
73
87
if (request ()->expectsJson ()) {
0 commit comments