private async Task <GeolocationDetails> CreateDetailsAsync(string ipOrUrl, GeolocationDetails newItem)
        {
            try
            {
                string accessKey = ipStackConfiguration.GetAccessKey();

                if (string.IsNullOrWhiteSpace(accessKey))
                {
                    throw new ApplicationException("Missing IP Stack access key setting.");
                }

                Interfaces.Data.GeolocationDetails details = await geolocationDetailsProvider.GetAsync(accessKey, ipOrUrl);

                if (details.Success == false)
                {
                    HandleUnsuccessfulDetailsRequest(details);
                }

                newItem.City        = details.City;
                newItem.CountryName = details.CountryName;
                newItem.ZipCode     = details.ZipCode;

                db.GeolocationDetails.Add(newItem);
                db.SaveChanges();

                return(newItem);
            }
            catch (Exception ex)
            {
                logger.LogError(this, ex);
                throw;
            }
        }
 private void HandleUnsuccessfulDetailsRequest(Interfaces.Data.GeolocationDetails details)
 {
     if (details.Error.Type == "invalid_access_key")
     {
         throw new Exception("Invalid access key.");
     }
     else
     {
         throw new Exception(details.Error.Info);
     }
 }