[backend/asp] Improve XML error responses
This commit is contained in:
parent
d6c8ecaee5
commit
e342d6f010
1 changed files with 19 additions and 4 deletions
|
@ -7,8 +7,8 @@ namespace Iceshrimp.Shared.Schemas.Web;
|
||||||
[XmlRoot("Error")]
|
[XmlRoot("Error")]
|
||||||
public class ErrorResponse
|
public class ErrorResponse
|
||||||
{
|
{
|
||||||
[XmlElement("Code")] public required int StatusCode { get; set; }
|
[XmlElement("Status")] public required int StatusCode { get; set; }
|
||||||
[XmlElement("Error")] public required string Error { get; set; }
|
[XmlElement("Error")] public required string Error { get; set; }
|
||||||
|
|
||||||
[XmlElement("Message")]
|
[XmlElement("Message")]
|
||||||
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
@ -22,10 +22,25 @@ public class ErrorResponse
|
||||||
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
public IDictionary<string, string[]>? Errors { get; set; }
|
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")]
|
[XmlElement("Source")]
|
||||||
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
[JI(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
public string? Source { get; set; }
|
public string? Source { get; set; }
|
||||||
|
|
||||||
[XmlElement("RequestId")]
|
[XmlElement("RequestId")] public required string RequestId { get; set; }
|
||||||
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; }
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue