private function retrieveErrorMessage()

in src/OSS/Result/Result.php [107:136]


    private function retrieveErrorMessage($body)
    {
        if (empty($body) || false === strpos($body, '<?xml')) {
            return '';
        }
        $flag = false;
        try {
            $xml = simplexml_load_string($body);
            if (isset($xml->Message)) {
                return strval($xml->Message);
            }
            $flag = true;
        } catch (\Exception $e) {
            $flag = true;
        }
        if ($flag === true) {
            $start = strpos($body, '<Message>');
            if ($start === false) {
                return '';
            }
            $start += 9;
            $end = strpos($body, '</Message>', $start);
            if ($end === false) {
                return '';
            }
            return substr($body, $start, $end - $start);
        }

        return '';
    }