@@ -21,9 +21,11 @@ function main() {
21
21
}
22
22
$ path = str_replace ("\\" , "/ " , $ path );
23
23
$ classShortName = $ path ;
24
- $ path = getenv ("DOCUMENT_ROOT " ) . "/ " . $ path . ".php " ;
24
+ $ docroot = getenv ("DOCUMENT_ROOT " );
25
+ if (empty ($ docroot )) $ docroot = ". " ;
26
+ $ path = $ docroot . "/ " . $ path . ".php " ;
25
27
if (!file_exists ($ path )) {
26
- throw new ClassNotFoundException ( $ classShortName );
28
+ trigger_error ( " Class not found: " . $ classShortName, E_USER_ERROR );
27
29
}
28
30
require_once ($ path );
29
31
});
@@ -45,7 +47,6 @@ function main() {
45
47
header ($ key . ": " . $ val );
46
48
}
47
49
}
48
- $ flags = (Common::isBrowser (getenv ("HTTP_USER_AGENT " )) ? JSON_PRETTY_PRINT : 0 );
49
50
$ json = [
50
51
"error " => [
51
52
"exception " => (new ReflectionClass ($ e ))->getShortName (),
@@ -54,12 +55,14 @@ function main() {
54
55
],
55
56
];
56
57
if (ini_get ("display_errors " )) {
57
- $ json ["error " ]["file " ] = Common::stripLeftPattern ($ e ->getFile (), "/home/nginx/bnetdocs-dev " );
58
+ $ json ["error " ]["file " ] = Common::stripLeftPattern (
59
+ $ e ->getFile (), getenv ("DOCUMENT_ROOT " )
60
+ );
58
61
$ json ["error " ]["line " ] = $ e ->getLine ();
59
62
}
60
63
Logger::logMetric ("error_data " , json_encode ($ json , JSON_PRETTY_PRINT ));
61
64
Logger::logException ($ e );
62
- die (json_encode ($ json , $ flags ));
65
+ die (json_encode ($ json , Common:: prettyJSONIfBrowser () ));
63
66
});
64
67
65
68
set_error_handler (function ($ errno , $ errstr , $ errfile , $ errline , $ errcontext ){
@@ -70,7 +73,6 @@ function main() {
70
73
header ("Content-Type: application/json;charset=utf-8 " );
71
74
header ("Expires: 0 " );
72
75
header ("Pragma: max-age=0 " );
73
- $ flags = (Common::isBrowser (getenv ("HTTP_USER_AGENT " )) ? JSON_PRETTY_PRINT : 0 );
74
76
$ json = [
75
77
"error " => [
76
78
"exception " => null ,
@@ -79,12 +81,14 @@ function main() {
79
81
];
80
82
if (ini_get ("display_errors " )) {
81
83
$ json ["error " ]["message " ] = $ errstr ;
82
- $ json ["error " ]["file " ] = Common::stripLeftPattern ($ errfile , "/home/nginx/bnetdocs-dev " );
84
+ $ json ["error " ]["file " ] = Common::stripLeftPattern (
85
+ $ errfile , getenv ("DOCUMENT_ROOT " )
86
+ );
83
87
$ json ["error " ]["line " ] = $ errline ;
84
88
}
85
89
Logger::logMetric ("error_data " , json_encode ($ json , JSON_PRETTY_PRINT ));
86
90
Logger::logError ($ errno , $ errstr , $ errfile , $ errline , $ errcontext );
87
- die (json_encode ($ json , $ flags ));
91
+ die (json_encode ($ json , Common:: prettyJSONIfBrowser () ));
88
92
});
89
93
90
94
Logger::initialize ();
0 commit comments