Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 25 additions & 21 deletions ToopherDotNet/ToopherDotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,31 +252,35 @@ private object request (string method, string endpoint, NameValueCollection para
response = wClient.DownloadString (client.RequestUrl);
}
} catch (WebException wex) {
IHttpWebResponse httpResp = HttpWebResponseWrapper.create(wex.Response);
string error_message;
using (Stream stream = httpResp.GetResponseStream ()) {
StreamReader reader = new StreamReader (stream, Encoding.UTF8);
error_message = reader.ReadToEnd ();
}
if (wex.Response != null) {
IHttpWebResponse httpResp = HttpWebResponseWrapper.create(wex.Response);
string error_message;
using (Stream stream = httpResp.GetResponseStream ()) {
StreamReader reader = new StreamReader (stream, Encoding.UTF8);
error_message = reader.ReadToEnd ();
}

String statusLine = httpResp.StatusCode.ToString () + " : " + httpResp.StatusDescription;
String statusLine = httpResp.StatusCode.ToString () + " : " + httpResp.StatusDescription;

if (String.IsNullOrEmpty (error_message)) {
throw new RequestError (statusLine);
} else {

try {
// Attempt to parse JSON response
var json = (JsonObject)SimpleJson.SimpleJson.DeserializeObject (error_message);
parseRequestError (json);
} catch (RequestError e) {
throw e;
} catch (Exception) {
throw new RequestError (statusLine + " : " + error_message);
}
}

if (String.IsNullOrEmpty (error_message)) {
throw new RequestError (statusLine);
throw new RequestError (error_message, wex);
} else {

try {
// Attempt to parse JSON response
var json = (JsonObject)SimpleJson.SimpleJson.DeserializeObject (error_message);
parseRequestError (json);
} catch (RequestError e) {
throw e;
} catch (Exception) {
throw new RequestError (statusLine + " : " + error_message);
}
throw new RequestError ("Unable to contact server", wex);
}

throw new RequestError (error_message, wex);
}

try {
Expand Down