private async Task GetTopic()

in code/PublishToEmbeddedSocial/EmbeddedSocial/EmbeddedSocial.cs [232:270]


        private async Task<TopicView> GetTopic(string topicName)
        {
            // get the handle for the topic name
            HttpOperationResponse<GetTopicByNameResponse> getTopicByNameOperationResponse = await this.client.Topics.GetTopicByNameWithHttpMessagesAsync(topicName: topicName, publisherType: PublisherType.App, authorization: this.authorization);

            // check response
            if (getTopicByNameOperationResponse == null || getTopicByNameOperationResponse.Response == null)
            {
                throw new Exception("got null response");
            }
            else if (!getTopicByNameOperationResponse.Response.IsSuccessStatusCode)
            {
                throw new Exception("request failed with HTTP code: " + getTopicByNameOperationResponse.Response.StatusCode + ", and reason: " + getTopicByNameOperationResponse.Response.ReasonPhrase);
            }
            else if (getTopicByNameOperationResponse.Body == null)
            {
                throw new Exception("got null response body");
            }
            else if (string.IsNullOrWhiteSpace(getTopicByNameOperationResponse.Body.TopicHandle))
            {
                throw new Exception("topicHandle is null or whitespace");
            }

            // get the topic
            string topicHandle = getTopicByNameOperationResponse.Body.TopicHandle;
            HttpOperationResponse<TopicView> getTopicOperationResponse = await this.client.Topics.GetTopicWithHttpMessagesAsync(topicHandle: topicHandle, authorization: this.authorization);

            // check response
            if (getTopicOperationResponse == null || getTopicOperationResponse.Response == null)
            {
                throw new Exception("got null response");
            }
            else if (!getTopicOperationResponse.Response.IsSuccessStatusCode)
            {
                throw new Exception("request failed with HTTP code: " + getTopicOperationResponse.Response.StatusCode + ", and reason: " + getTopicOperationResponse.Response.ReasonPhrase);
            }

            return getTopicOperationResponse.Body;
        }