/** * keep backward compatibility with changed error codes * @param KalturaAPIException $e * @throws KalturaAPIException */ private function throwTranslatedException(KalturaAPIException $e) { $code = $e->getCode(); if ($code == KalturaErrors::USER_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND); } else { if ($code == KalturaErrors::WRONG_OLD_PASSWORD) { throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_WRONG_OLD_PASSWORD, "wrong password"); } else { if ($code == KalturaErrors::USER_WRONG_PASSWORD) { throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND); } else { if ($code == KalturaErrors::LOGIN_DATA_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::ADMIN_KUSER_NOT_FOUND); } } } } throw $e; }
<th>Error message</th> </tr> <?php $odd = true; foreach ($generalError as $error => $errorParams) { ?> <tr class="<?php echo $odd ? "odd" : ""; ?> "> <?php $ex = new KalturaAPIException(null); call_user_func_array(array($ex, 'KalturaAPIException'), array_merge(array($error), $errorParams)); ?> <td><?php echo $ex->getCode(); ?> </td> <td><?php echo $ex->getMessage(); ?> </td> </tr> <?php $odd = !$odd; } ?> </table> <p> Example of an error Response
protected function handleErrorMapping(KalturaAPIException $apiException, $service, $action) { if (!kConf::hasParam('api_strict_error_map')) { KalturaLog::err('api_strict_error_map was not found in kConf and is mandatory!'); return new KalturaAPIException(KalturaErrors::INTERNAL_SERVERL_ERROR); } $map = kConf::get('api_strict_error_map'); if (!is_array($map)) { return $apiException; } $mapKey = strtolower($service) . '_' . strtolower($action); if (!isset($map[$mapKey])) { return $apiException; } $mapParams = $map[$mapKey]; $defaultError = isset($mapParams['defaultError']) ? $mapParams['defaultError'] : null; $defaultNull = isset($mapParams['defaultNull']) ? $mapParams['defaultNull'] : null; $whiteListedErrors = isset($mapParams['whitelisted']) ? $mapParams['whitelisted'] : array(); if (!is_array($whiteListedErrors)) { $whiteListedErrors = array(); } if (array_search($apiException->getCode(), $whiteListedErrors, true) !== false) { KalturaLog::debug('Returning white-listed error: ' . $apiException->getCode()); return $apiException; } // finally, replace the error or return null as default if ($defaultNull) { KalturaLog::debug('Replacing error code "' . $apiException->getCode() . '" with null result'); return null; } else { $reflectionException = new ReflectionClass("KalturaAPIException"); $errorStr = constant($defaultError); $args = array_merge(array($errorStr), $apiException->getArgs()); /** @var KalturaAPIException $replacedException */ $replacedException = $reflectionException->newInstanceArgs($args); KalturaLog::debug('Replacing error code "' . $apiException->getCode() . '" with error code "' . $replacedException->getCode() . '"'); return $replacedException; } }
public function initService($serviceId, $serviceName, $actionName) { // init service and action name $this->serviceId = $serviceId; $this->serviceName = $serviceName; $this->actionName = $actionName; // impersonated partner = partner parameter from the request $this->impersonatedPartnerId = kCurrentContext::$partner_id; $this->ks = kCurrentContext::$ks_object ? kCurrentContext::$ks_object : null; // operating partner = partner from the request or the ks partner $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; // if there is no session, assume it's partner 0 using actions that doesn't require ks if (is_null($partnerId)) { $partnerId = 0; } $this->partner = PartnerPeer::retrieveByPK($partnerId); if (!$this->partner) { $this->partner = null; } // check if current aciton is allowed and if private partner data access is allowed $allowPrivatePartnerData = false; $actionPermitted = $this->isPermitted($allowPrivatePartnerData); // action not permitted at all, not even kaltura network if (!$actionPermitted) { $e = new KalturaAPIException(APIErrors::SERVICE_FORBIDDEN, $this->serviceId . '->' . $this->actionName); //TODO: should sometimes thorow MISSING_KS instead header("X-Kaltura:error-" . $e->getCode()); header("X-Kaltura-App: exiting on error " . $e->getCode() . " - " . $e->getMessage()); throw $e; } // init partner filter parameters $this->private_partner_data = $allowPrivatePartnerData; $this->partnerGroup = kPermissionManager::getPartnerGroup($this->serviceId, $this->actionName); if ($this->globalPartnerAllowed($this->actionName)) { $this->partnerGroup = PartnerPeer::GLOBAL_PARTNER . ',' . trim($this->partnerGroup, ','); } // apply partner filters according to current context and permissions myPartnerUtils::resetAllFilters(); myPartnerUtils::applyPartnerFilters($partnerId, $this->private_partner_data, $this->partnerGroup, $this->kalturaNetworkAllowed($this->actionName)); }