Skip to content

Commit

Permalink
(GH-1172) Show web status code in failure
Browse files Browse the repository at this point in the history
If a package is not installed due to web errors, note the status
code as part of the failure.
  • Loading branch information
ferventcoder committed Feb 27, 2017
1 parent 4e43c96 commit 96d52c5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Expand Up @@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.app.services
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using NuGet;
using adapters;
using commandline;
Expand Down Expand Up @@ -468,7 +469,15 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult> c
}
catch (Exception ex)
{
var logMessage = "{0} not installed. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message);
var message = ex.Message;
var webException = ex as System.Net.WebException;
if (webException != null)
{
var response = webException.Response as HttpWebResponse;
if (response != null && !string.IsNullOrWhiteSpace(response.StatusDescription)) message += " {0}".format_with(response.StatusDescription);
}

var logMessage = "{0} not installed. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, message);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
var errorResult = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, version.to_string(), null));
errorResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
Expand Down Expand Up @@ -748,7 +757,15 @@ public void remove_rollback_directory_if_exists(string packageName)
}
catch (Exception ex)
{
var logMessage = "{0} not upgraded. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, ex.Message);
var message = ex.Message;
var webException = ex as System.Net.WebException;
if (webException != null)
{
var response = webException.Response as HttpWebResponse;
if (response != null && !string.IsNullOrWhiteSpace(response.StatusDescription)) message += " {0}".format_with(response.StatusDescription);
}

var logMessage = "{0} not upgraded. An error occurred during installation:{1} {2}".format_with(packageName, Environment.NewLine, message);
this.Log().Error(ChocolateyLoggers.Important, logMessage);
packageResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
if (packageResult.ExitCode == 0) packageResult.ExitCode = 1;
Expand Down

0 comments on commit 96d52c5

Please sign in to comment.