diff --git a/classes/collabora.php b/classes/collabora.php index 278fd6f..032b996 100644 --- a/classes/collabora.php +++ b/classes/collabora.php @@ -287,6 +287,11 @@ private function get_discovery_xml() { $url = rtrim($baseurl, '/').'/hosting/discovery'; $curl = new \curl(); $xml = $curl->get($url); + if ($curl->get_errno()) { + // $xml possibly contains some error message, which isn't a valid xml. + return ''; // TODO: throw exception to avoid causing secondary errors. + } + $cache->set($baseurl, $xml); } return $xml; @@ -299,8 +304,12 @@ private function get_discovery_xml() { * @return string */ private function get_url_from_mimetype($discoveryxml, $mimetype) { - $xml = new \SimpleXMLElement($discoveryxml); - $app = $xml->xpath("//app[@name='{$mimetype}']"); + $app = null; + if ($discoveryxml) { + $xml = new \SimpleXMLElement($discoveryxml); + $app = $xml->xpath("//app[@name='{$mimetype}']"); + } + if (!$app) { throw new \moodle_exception('unsupportedtype', 'mod_collabora', '', $mimetype); }