/** * Valid responses from read methods * * @param String $response The XML response string * * @throws Exception * @return null */ private static function validateReadResults($response) { // don't send warnings to the error log libxml_use_internal_errors(true); $simpleXml = simplexml_load_string($response); libxml_use_internal_errors(false); if ($simpleXml === false) { return; // the result is csv or json, so there's no error } // Is there a problem with the XML request? if ((string) $simpleXml->operation->result->status == 'false') { $error = $simpleXml->operation->errormessage[0]; throw new Exception("[Error] " . api_util::xmlErrorToString($error)); } // is there a problem with the method invocation? $status = $simpleXml->operation->result->status; if ((string) $status != 'success') { $error = $simpleXml->operation->result->errormessage; throw new Exception("[Error] " . api_util::xmlErrorToString($error)); } else { return; // no error found. } }
/** * Validate the repsonse from Intacct to see if we successfully created a session * * @param String $response The XML response from Intacct * * @throws Exception * @return null */ private static function validateConnection($response) { $simpleXml = simplexml_load_string($response); if ($simpleXml === false) { throw new Exception("Invalid XML response: \n" . var_export($response, true)); } if ((string) $simpleXml->control->status == 'failure') { throw new Exception(api_util::xmlErrorToString($simpleXml->errormessage)); } if (!isset($simpleXml->operation)) { if (isset($simpleXml->errormessage)) { throw new Exception(api_util::xmlErrorToString($simpleXml->errormessage->error[0])); } } if (isset($simpleXml->operation->authentication->status)) { if ($simpleXml->operation->authentication->status != 'success') { $error = $simpleXml->operation->errormessage; throw new Exception(" [Error] " . (string) $error->error[0]->description2); } } $status = $simpleXml->operation->result->status; if ((string) $status != 'success') { $error = $simpleXml->operation->result->errormessage; throw new Exception(" [Error] " . (string) $error->error[0]->description2); } else { return; // no error found. } }