/** * Check for server error. Return null, string or object, based on configuration * * @param string $content * @param bool $useCache * @return mixed */ protected function handleContent($content, &$useCache = true) { if (is_null($content)) { return null; } $errorCode = 0; $errorText = ''; //get error code and error mesage first, I'm using xpath because I could pull it from config later $this->xml = new SimpleXMLElement($content); if ($this->config['serverError'] != 'ignore') { $xerrorCode = $this->xml->xpath('/eveapi/error/@code'); $xerrorText = $this->xml->xpath('/eveapi/error/text()'); if ($xerrorCode) { $errorCode = (int) $xerrorCode[0]; } if ($xerrorText) { $errorText = (string) $xerrorText[0]; } } if (in_array($errorCode, $this->config['cacheUpdateError'])) { $this->cache->updateCachedUntil((string) $this->xml->cachedUntil); } //if we found an error if ($errorCode || $errorText) { //we do not want to cache error, right? $useCache = false; switch ($this->config['serverError']) { case 'returnParsed': break; case 'returnNull': return null; break; case 'throwException': default: if (100 <= $errorCode && $errorCode < 200) { throw new AleExceptionEVEUserInput($errorText, $errorCode, (string) $this->xml->cachedUntil); } elseif (200 <= $errorCode && $errorCode < 300) { throw new AleExceptionEVEAuthentication($errorText, $errorCode, (string) $this->xml->cachedUntil); } elseif (500 <= $errorCode && $errorCode < 600) { throw new AleExceptionEVEServerError($errorText, $errorCode, (string) $this->xml->cachedUntil); } else { throw new AleExceptionEVEMiscellaneous($errorText, $errorCode, (string) $this->xml->cachedUntil); } } } $parserClass = $this->config['parserClass']; //check if we have result we want if (strtolower($parserClass) == strtolower('SimpleXMLElement') && isset($this->xml)) { return $this->xml; } return parent::handleContent($content, $useCache); }
/** * Check for server error. Return null, string or object, based on configuration * * @param string $content * @param bool $useCache * @return mixed */ protected function handleContent($content, &$useCache = true) { if (is_null($content)) { return null; } $errorCode = 0; $errorText = ''; $this->scanContent($content, $errorCode, $errorText); //if we found an error if ($errorCode || $errorText) { //we want to update cached until $this->cache->updateCachedUntil($this->cachedUntil); //but we do not want to cache error, right? $useCache = false; switch ($this->config['serverError']) { case 'returnParsed': break; case 'returnNull': return null; break; case 'throwException': default: if (100 <= $errorCode && $errorCode < 200) { throw new AleExceptionEVEUserInput($errorText, $errorCode, (string) $this->cachedUntil); } elseif (200 <= $errorCode && $errorCode < 300) { throw new AleExceptionEVEAuthentication($errorText, $errorCode, (string) $this->cachedUntil); } elseif (500 <= $errorCode && $errorCode < 600) { throw new AleExceptionEVEServerError($errorText, $errorCode, (string) $this->cachedUntil); } else { throw new AleExceptionEVEMiscellaneous($errorText, $errorCode, (string) $this->cachedUntil); } } } return parent::handleContent($content, $useCache); }