/** * The error returned by OData service will be in Atom format in this case * AtomParser will be used to retrive exact error from the atom, if some * other error happens for example, if credentials are wrong, in this case * IIS will retruns error in plain string format. * * @param string $errorStr Error String as plain string or Atom format * @param string $content_type */ public function ODataServiceException($errorStr, $content_type = '', $headers = array(), $statusCode = '') { $this->_headers = $headers; $this->_statusCode = $statusCode; AtomParser::GetErrorDetails($errorStr, $this->_error, $this->_detailedError, $content_type); }
/** * Execute a Http request and returns the Http Response. If any error happens * then the $isError flag will be set to true and $innerException will * contain the exception string. From the returned http response object more * details (http headers, code, message and body) can be retrieved. * [Note: Do not call this function from your application, it is used internally] * * @param HttpRequest $httpRequest * @param string $dataServiceVersion * @param boolean [out] $isError * @param string [out] $innerException * @return HttpResponse */ public function ExecuteAndReturnResponse($httpRequest, $dataServiceVersion, &$isError, &$innerException) { $this->OnBeforeRequestInternal($httpRequest); $httpRawResponse = ''; //need a try catch, because during curl_exec, if curl failed to //connet to the OData Service it will throw InvalidOperation //exception try { $httpRawResponse = $httpRequest->GetResponse(); } catch (InvalidOperation $exception) { $isError = true; $innerException = $exception->getError() . $exception->getDetailedError(); return new Microsoft_Http_Response('404', array()); } $httpResponse = HttpResponse::fromString($httpRawResponse); $this->OnAfterResponseInternal($httpResponse); $isError = $httpResponse->IsError(); $headers = $httpResponse->getHeaders(); if ($isError) { if (isset($headers[HttpRequestHeader::ContentType])) { if (strpos(strtolower($headers[HttpRequestHeader::ContentType]), strtolower(Resource::Content_Type_ATOM)) !== FALSE) { $innerException = $httpResponse->getMessage(); } else { $outerError = $innerError = null; /*The error string can be in the format: retrive the error <?xml version="1.0" encoding="utf-8" standalone="yes"?> <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code></code> <message xml:lang="en-US">The error</message> </error>*/ AtomParser::GetErrorDetails($httpResponse->getBody(), $outerError, $innerError); $innerException = $outerError . "<br/>" . $innerError; } } else { $innerException = $httpResponse->getMessage(); } } if (isset($headers['Dataserviceversion']) && (int) $headers['Dataserviceversion'] > (int) $dataServiceVersion) { $isError = true; $innerException = Resource::VersionMisMatch . $headers['Dataserviceversion']; } return $httpResponse; }