编码-错误情形统一优先处理

$lastId = $arrInput['params']['last_id'];
$qlistRet = $this->_objApiQlUlist->getUlistStream($uid, null, self::PAGE_LIMIT+1, $lastId);
if($qlistRet['errno'] != 0){                                                            ---->接口调用出错情况
  $errno = Dcna_ExceptionCodes::UNKNOWN_ERROR;
  $errmsg = Dcna_ExceptionCodes::$errInfo[$errno];
  $arrResult['errno'] = $errno;
  $arrResult['errmsg'] = $errmsg;

  return $arrResult;
}

if(empty($qlistRet['data'])){                                                       ---->数据为空情况
  $errno = Dcna_ExceptionCodes::EMPTY_DATA_ERROR;
  $errmsg = Dcna_ExceptionCodes::$errInfo[$errno];
  $arrResult['errno'] = $errno;
  $arrResult['errmsg'] = $errmsg;

  return $arrResult;
}

                                          ---->下面的代码直接处理数据,而无需再对数据进行检查判断     

if(count($qlistRet['data']) == self::PAGE_LIMIT+1 ){
$arrResult['data']['has_more'] = 1;
}
$qids = array();
$relQids = array();
$list_count = 0;
foreach($qlistRet['data'] as $one){
  $qids[] = $one['qid'];
  $relQids[$one['qid']] = $one;
  $list_count++;
  if($list_count == self::PAGE_LIMIT){
  break;
  }
}

 

posted on 2015-05-08 17:13  wzl_lukas  阅读(149)  评论(0编辑  收藏  举报