[backend/asp] Improve XML error responses

This commit is contained in:
Laura Hausmann 2024-08-16 01:34:43 +02:00
parent d6c8ecaee5
commit e342d6f010
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -7,8 +7,8 @@ namespace Iceshrimp.Shared.Schemas.Web;
[XmlRoot("Error")]
public class ErrorResponse
{
[XmlElement("Code")] public required int StatusCode { get; set; }
[XmlElement("Error")] public required string Error { get; set; }
[XmlElement("Status")] public required int StatusCode { get; set; }
[XmlElement("Error")] public required string Error { get; set; }
[XmlElement("Message")]
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
@ -22,10 +22,25 @@ public class ErrorResponse
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IDictionary<string, string[]>? Errors { get; set; }
[XmlArray("ValidationErrors")]
[XmlArrayItem("Error")]
[JI]
public XmlValidationError[]? XmlErrors
{
get => Errors?.SelectMany(x => x.Value.Select(i => new XmlValidationError { Element = x.Key, Error = i }))
.ToArray();
set => Errors = value?.ToDictionary(p => p.Element, p => (string[]) [p.Error]);
}
[XmlElement("Source")]
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Source { get; set; }
[XmlElement("RequestId")]
public required string RequestId { get; set; }
[XmlElement("RequestId")] public required string RequestId { get; set; }
}
public class XmlValidationError
{
[XmlAttribute("Element")] public required string Element { get; set; }
[XmlAttribute("Error")] public required string Error { get; set; }
}