You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/Emby.Dlna/Service/ControlErrorHandler.cs

57 lines
1.8 KiB

#pragma warning disable CS1591
using System;
using System.IO;
using System.Text;
using System.Xml;
using Emby.Dlna.Didl;
namespace Emby.Dlna.Service
{
public static class ControlErrorHandler
{
4 years ago
private const string NsSoapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
public static ControlResponse GetResponse(Exception ex)
{
var settings = new XmlWriterSettings
{
Encoding = Encoding.UTF8,
CloseOutput = false
};
StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
using (var writer = XmlWriter.Create(builder, settings))
{
writer.WriteStartDocument(true);
4 years ago
writer.WriteStartElement("SOAP-ENV", "Envelope", NsSoapEnv);
writer.WriteAttributeString(string.Empty, "encodingStyle", NsSoapEnv, "http://schemas.xmlsoap.org/soap/encoding/");
4 years ago
writer.WriteStartElement("SOAP-ENV", "Body", NsSoapEnv);
writer.WriteStartElement("SOAP-ENV", "Fault", NsSoapEnv);
writer.WriteElementString("faultcode", "500");
writer.WriteElementString("faultstring", ex.Message);
writer.WriteStartElement("detail");
writer.WriteRaw("<UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>401</errorCode><errorDescription>Invalid Action</errorDescription></UPnPError>");
8 years ago
writer.WriteFullEndElement();
8 years ago
writer.WriteFullEndElement();
writer.WriteFullEndElement();
8 years ago
writer.WriteFullEndElement();
writer.WriteEndDocument();
}
return new ControlResponse
{
Xml = builder.ToString(),
IsSuccessful = false
};
}
}
}