Permalink
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (32 sloc) 1.05 KB
<?php
header("Content-Type: application/javascript");
// TODO refactor with json.php
function my_content_type_exception_handler($e) {
$message = "Error: " . htmlspecialchars($e->getMessage());
if (is_localhost()) {
// only display trace locally
$message .= "\nTrace:" . print_exception_trace_js($e);
}
echo "alert(" . json_encode($message) . ");";
}
function print_exception_trace_js($e) {
if (!$e) {
return "null";
}
if (!($e instanceof Exception)) {
return "Not exception: " . get_class($e) . ": " . print_r($e, true) . "";
}
$string = "";
$string .= $e->getMessage() . " (" . get_class($e) . ")\n";
$string .= "* " . $e->getFile() . "#" . $e->getLine() . "\n";
foreach ($e->getTrace() as $e2) {
$string .= " * " . $e2['file'] . "#" . $e2['line'] . ": " . $e2['function'] . (isset($e2['args']) ? format_args_list($e2['args']) : "") . "\n";
}
if ($e->getPrevious()) {
$string .= "Caused by:";
$string .= print_exception_trace($e->getPrevious());
$string .= "\n";
}
$string .= "\n";
return $string;
}