function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (!$this->initFinished) { $isApiError = false; } else { $request = Zend_Controller_Front::getInstance()->getRequest(); $isApiError = preg_match('#^/api/#', $request->getPathInfo()) && !preg_match('#^/api/admin($|/)#', $request->getPathInfo()); } if (!$isApiError && (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing')) { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); $display_title = $e->getPublicTitle(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } /// special handling for API errors if ($isApiError) { $format = $request->getParam('_format', 'json'); if (!empty($display_title)) { $display_error = $display_title . ':' . $display_error; } $display_error = trim($display_error, " \t\n\r"); if ($format == 'xml') { $xml = new SimpleXMLElement('<error />'); $xml->ok = 'false'; $xml->message = $display_error; echo (string) $xml; } else { echo json_encode(array('ok' => false, 'error' => true, 'message' => $display_error)); } exit; } if (!$this->initFinished) { amDie($display_error); } // fixes http://bt.amember.com/issues/597 if (($router = Zend_Controller_Front::getInstance()->getRouter()) instanceof Zend_Controller_Router_Rewrite) { $router->addDefaultRoutes(); } // $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! if (isset($display_title)) { $t->assign('title', $display_title); } $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }
function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing') { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }