@@ -17,51 +17,64 @@ public function __construct() {
17
17
}
18
18
19
19
public function run () {
20
- // Process the request first
21
- $ rc = $ this ->page ->processRequest ();
22
- $ action = is_array ($ rc ) ? $ rc [0 ] : $ rc ;
23
-
24
- // Render when required
25
- if ($ action == 'render ' ) {
26
- Log::debug ('$_SERVER= ' , $ _SERVER );
27
- Log::debug ('Request= ' , $ this ->app ->request );
28
- $ this ->theme ->render ($ this ->page );
29
- Session \Utils::isFreshLogin ();
30
- } else if ($ action == 'redirect ' ) {
31
- // redirect
32
- $ this ->app ->afterRequest ();
33
- header ('Location: ' .$ rc [1 ]);
20
+ try {
21
+ // Process the request first
22
+ $ rc = $ this ->page ->processRequest ();
23
+ $ action = is_array ($ rc ) ? $ rc [0 ] : $ rc ;
24
+
25
+ // Render when required
26
+ if ($ action == 'render ' ) {
27
+ Log::debug ('$_SERVER= ' , $ _SERVER );
28
+ Log::debug ('Request= ' , $ this ->app ->request );
29
+ $ this ->theme ->render ($ this ->page );
30
+ Session \Utils::isFreshLogin ();
31
+ } else if ($ action == 'redirect ' ) {
32
+ // redirect
33
+ $ this ->app ->afterRequest ();
34
+ header ('Location: ' .$ rc [1 ]);
35
+ }
36
+ } catch (\Throwable $ e ) {
37
+ \TgLog \Log::error ('Cannot create application ' , $ e );
38
+ $ page = new Error \Error500 ($ this ->app , $ e );
39
+ $ page ->processRequest ();
40
+ $ this ->theme ->render ($ page );
34
41
}
42
+
35
43
$ this ->app ->afterRequest ();
36
44
}
37
45
38
46
39
47
protected function createPage () {
40
- $ request = $ this ->app ->request ;
41
-
42
- // Check the path info
43
- $ canonical = $ this ->app ->router ->getCanonicalPath ();
44
- $ requested = $ request ->originalPath ;
45
- if ($ requested != $ canonical ) {
46
- $ params = $ request ->params ;
47
- if ($ params ) $ params = '? ' .$ params ;
48
- header ('Location: ' .$ canonical .$ params );
49
- exit ;
50
- }
51
-
52
- // Try to find the correct page
53
- $ page = $ this ->app ->router ->getPage ();
54
-
55
- // Get a specific error page from the theme
56
- if ($ page == NULL ) {
57
- $ page = $ this ->theme ->getErrorPage (404 );
58
- }
59
-
60
- // Get the default error page
61
- if ($ page == NULL ) {
62
- $ page = new Error \Error404 ($ this ->app );
48
+ try {
49
+ $ request = $ this ->app ->request ;
50
+
51
+ // Check the path info
52
+ $ canonical = $ this ->app ->router ->getCanonicalPath ();
53
+ $ requested = $ request ->originalPath ;
54
+ if ($ requested != $ canonical ) {
55
+ $ params = $ request ->params ;
56
+ if ($ params ) $ params = '? ' .$ params ;
57
+ header ('Location: ' .$ canonical .$ params );
58
+ exit ;
59
+ }
60
+
61
+ // Try to find the correct page
62
+ $ page = $ this ->app ->router ->getPage ();
63
+
64
+ // Get a specific error page from the theme
65
+ if ($ page == NULL ) {
66
+ $ page = $ this ->theme ->getErrorPage (404 );
67
+ }
68
+
69
+ // Get the default error page
70
+ if ($ page == NULL ) {
71
+ $ page = new Error \Error404 ($ this ->app );
72
+ }
73
+ return $ page ;
74
+ } catch (\Throwable $ e ) {
75
+ \TgLog \Log::error ('Cannot create application ' , $ e );
76
+ return new Error \Error500 ($ this ->app , $ e );
63
77
}
64
- return $ page ;
65
78
}
66
79
67
80
protected function createApp () {
0 commit comments