Connectster.Shopify.ShopifyCommunicator.ShopifyDelete C# (CSharp) Method

ShopifyDelete() private method

private ShopifyDelete ( string path, string storePassword ) : XmlDocument
path string
storePassword string
return System.Xml.XmlDocument
        private XmlDocument ShopifyDelete(string path, string storePassword)
        {
            var deleteRequest = (HttpWebRequest) WebRequest.Create(path);
            deleteRequest.Method = "DELETE";

            var cCache = new CredentialCache();
            cCache.Add(new Uri(path), "Basic", new NetworkCredential(_appAuth.User, storePassword));
            deleteRequest.Credentials = cCache;
            deleteRequest.KeepAlive = false;

            try
            {
                ApiLogger.DebugFormat("ShopifyCommunicator::ShopifyDelete(): attempting DELETE request to ({0})", path);
                var deleteResponse = (HttpWebResponse) deleteRequest.GetResponse();
                ApiLogger.DebugFormat("ShopifyCommunicator::ShopifyDelete(): Received HttpStatusCode ({0})",
                                      deleteResponse.StatusCode);

                if (deleteResponse.StatusCode == HttpStatusCode.OK)
                {
                    // return null indicates success
                    deleteResponse.Close();
                    return null;
                }
            }
            catch (WebException we)
            {
                var deleteResponse = (HttpWebResponse) we.Response;
                if (deleteResponse != null)
                {
                    if (deleteResponse.Headers.AllKeys.Contains("Status"))
                    {
                        if (deleteResponse.Headers["Status"] == "404")
                        {
                            ApiLogger.WarnFormat(
                                "ShopifyCommunicator::ShopifyDelete():: WebException Thrown: Http 404. Path is ({0})",
                                path);
                            return null; //If its not there, good!
                        }
                        if (deleteResponse.Headers["Status"] == "401")
                        {
                            ApiLogger.WarnFormat(
                                "ShopifyCommunicator::ShopifyDelete():: WebException Thrown: Http 401. Invalid Authentication. Path is ({0})",
                                path);
                        }
                    }

                    ApiLogger.ErrorFormat(
                        "ShopifyCommunicator::ShopifyDelete(): Error HTTP DELETE url={0} . Server Response={1}", path,
                        deleteResponse.StatusCode);

                    var reader = new StreamReader(deleteResponse.GetResponseStream());
                    string responseMessage = reader.ReadToEnd();
                    // Cleanup the streams and the response.
                    reader.Close();
                    we.Response.Close();

                    XmlDocument errorDoc = IsValidXml(responseMessage); //returns XmlDocument if valid error, or null.
                    if (errorDoc == null)
                    {
                        errorDoc = IsValidXml("<error>" + responseMessage + "\n</error>");
                    }
                    return errorDoc;
                }
            }

            Logger.WarnFormat("ShopifyCommunicator::ShopifyDelete(): returning null XmlDocument.");
            return null;
        }