protected function getErrorCodeFromServiceException(ServiceException $exception) { $xml = @simplexml_load_string($exception->getErrorReason()); if ($xml && isset($xml->Code)) { return (string) $xml->Code; } return $exception->getErrorReason(); }