Exemplo n.º 1
0
 public function renderError($error)
 {
     if (strpos($error['msg'], 'swoole_client::connect()') !== false) {
         return;
     }
     $response = DI::getDefault()->getShared('response');
     switch ($error['code']) {
         case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
         case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
             $response->setStatusCode(404);
             break;
         case Dispatcher::EXCEPTION_INVALID_HANDLER:
         case Dispatcher::EXCEPTION_INVALID_PARAMS:
             $response->setStatusCode(400);
             break;
         case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
             $response->setStatusCode(508);
             break;
             //代码:0
         //代码:0
         case Dispatcher::EXCEPTION_NO_DI:
             //notice错误
         //notice错误
         case 8:
             //trigger_error()
             //用户主动产生的警告或通知
         //trigger_error()
         //用户主动产生的警告或通知
         case 256:
         case 512:
         case 1024:
         case 16384:
             break;
         default:
             $response->setStatusCode(503);
             break;
     }
     if (!$response->issent()) {
         $response->sendHeaders();
         Monitor::pushError();
         $config = DI::getDefault()->getShared('config');
         if (property_exists($config, 'errorHandler')) {
             if (class_exists($config->errorHandler)) {
                 $class = new $config->errorHandler();
                 if (method_exists($class, 'showmsg')) {
                     APP_ENV == 'product' && ($error['trace'] = '');
                     $class->showmsg($error, 'danger');
                     exit;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 虚拟本地并行调用(纯本地)
  * 目的:尽可能的做到与远程调取无缝对接
  * @param  array $data 暂不考虑error_callback
  * @return array 返回不调取回调函数的值
  */
 public function callMulti($data = array())
 {
     if (empty($data)) {
         return false;
     }
     $result = array();
     foreach ($data as $k => $v) {
         $callback = isset($v['callback']) ? $v['callback'] : null;
         $parameters = array('service' => $v['service'], 'method' => $v['method'], 'args' => isset($v['args']) ? $v['args'] : array());
         $tmpRes = $this->call($parameters);
         Monitor::pushMsg($v, $tmpRes);
         if (empty($callback)) {
             $result[$k + 1] = $tmpRes;
         } elseif (is_array($callback)) {
             call_user_func_array($callback, array($tmpRes, ''));
         } else {
             //抛异常
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 private function pushError($rawData, $error)
 {
     $di = \Phalcon\DI::getDefault();
     if (isset($di['request'])) {
         $error['url'] = $di['request']->getHttpHost() . $di['request']->getUri();
     }
     $error['callinfo'] = json_encode($rawData);
     $error['app'] = Monitor::getProject();
     $error['serverip'] = sprintf("%u\n", ip2long(Monitor::getLocalip()));
     $this->swooleCall(array('service' => 'Api\\Services\\Monitor', 'method' => 'addlog', 'args' => array($error)));
 }