Skip to content

Commit

Permalink
Don't try to read error if it isn't permitted
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Jul 28, 2014
1 parent f575af8 commit a2f9c18
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions Raven.Studio/Models/ApplicationModel.cs
Expand Up @@ -204,28 +204,30 @@ public static List<object> ExtractError(Stream stream, HttpWebResponse httpWebRe

public static List<object> ExtractError(Stream stream, HttpWebResponse httpWebResponse, IEnumerable<object> details)
{
var error = new StreamReader(stream).ReadToEnd();

var objects = new List<object>(details);
try
{
var item = RavenJObject.Parse(error);
objects.Insert(0, "Server Error:");
objects.Insert(1, "-----------------------------------------");
objects.Insert(2, item.Value<string>("Url"));
objects.Insert(3, item.Value<string>("Error"));
objects.Insert(4, "-----------------------------------------");
objects.Insert(5, Environment.NewLine);
objects.Insert(6, Environment.NewLine);
}
catch (Exception)
if (stream.CanRead)
{
objects.Insert(0, "Server sent:");
objects.Insert(1, error);
objects.Insert(2, Environment.NewLine);
objects.Insert(3, Environment.NewLine);
}
var error = new StreamReader(stream).ReadToEnd();

try
{
var item = RavenJObject.Parse(error);
objects.Insert(0, "Server Error:");
objects.Insert(1, "-----------------------------------------");
objects.Insert(2, item.Value<string>("Url"));
objects.Insert(3, item.Value<string>("Error"));
objects.Insert(4, "-----------------------------------------");
objects.Insert(5, Environment.NewLine);
objects.Insert(6, Environment.NewLine);
}
catch (Exception)
{
objects.Insert(0, "Server sent:");
objects.Insert(1, error);
objects.Insert(2, Environment.NewLine);
objects.Insert(3, Environment.NewLine);
}
}
if (httpWebResponse.StatusCode == HttpStatusCode.Unauthorized)
{
objects.Insert(0, "Could not get authorization for this command.");
Expand Down

0 comments on commit a2f9c18

Please sign in to comment.