private void Client_DownloadStringCompleted(object sender, CapsBase.DownloadStringCompletedEventArgs e)
{
if (OnComplete != null && !e.Cancelled)
{
if (e.Error == null)
{
OSD result = OSDParser.DeserializeLLSDXml(e.Result);
try { OnComplete(this, result, e.Error); }
catch (Exception ex) { Logger.Log.Error(ex.Message, ex); }
}
else
{
// Some error occurred, try to figure out what happened
HttpStatusCode code = HttpStatusCode.OK;
if (e.Error is WebException && ((WebException)e.Error).Response != null)
code = ((HttpWebResponse)((WebException)e.Error).Response).StatusCode;
if (code == HttpStatusCode.BadGateway)
{
// This is not good (server) protocol design, but it's normal.
// The CAPS server is a proxy that connects to a Squid
// cache which will time out periodically. The CAPS server
// interprets this as a generic error and returns a 502 to us
// that we ignore
StartRequest(_PostData, _ContentType);
}
else if (code != HttpStatusCode.OK)
{
// Status code was set to something unknown, this is a failure
Logger.Log.DebugFormat("Caps error at {0}: {1}", _Client.Location, code);
try { OnComplete(this, null, e.Error); }
catch (Exception ex) { Logger.Log.Error(ex.Message, ex); }
}
else
{
// Status code was not set, some other error occurred. This is a failure
Logger.Log.DebugFormat("Caps error at {0}: {1}", _Client.Location, e.Error.Message);
try { OnComplete(this, null, e.Error); }
catch (Exception ex) { Logger.Log.Error(ex.Message, ex); }
}
}
}
else if (e.Cancelled)
{
Logger.Log.Debug("Capability action at " + _Client.Location + " cancelled");
}
}