diff --git a/Pleroma/Models/PleromaException.cs b/Pleroma/Models/PleromaException.cs index e5d5ada..b891fee 100644 --- a/Pleroma/Models/PleromaException.cs +++ b/Pleroma/Models/PleromaException.cs @@ -1,31 +1,32 @@ namespace Uwaa.Pleroma; -public class PleromaException : Exception +public abstract class PleromaException : Exception +{ + public override string ToString() => Message; +} + +public class PleromaSimpleException : PleromaException { [JsonPropertyName("error")] public string Text { get; set; } = null!; public override string Message => Text; - - public override string ToString() => Message; } -public class PleromaAggregateException : Exception +public class PleromaAggregateException : PleromaException { [JsonPropertyName("errors")] public PleromaInnerException[] Text { get; set; } = null!; public override string Message => string.Join("\n", (object?[])Text); - public override string ToString() => Message; + public override Exception GetBaseException() => Text == null ? this : Text[0]; } -public class PleromaInnerException : Exception +public class PleromaInnerException : PleromaException { [JsonPropertyName("detail")] public string Text { get; set; } = null!; public override string Message => Text; - - public override string ToString() => Message; } \ No newline at end of file diff --git a/Pleroma/Pleroma.cs b/Pleroma/Pleroma.cs index daafea4..7afca23 100644 --- a/Pleroma/Pleroma.cs +++ b/Pleroma/Pleroma.cs @@ -69,7 +69,7 @@ public class Pleroma { try { - PleromaException? err = JsonSerializer.Deserialize(text, SerializerOptions); + PleromaSimpleException? err = JsonSerializer.Deserialize(text, SerializerOptions); if (err != null && err.Text != null) { if (err.Text == "Throttled") @@ -85,7 +85,7 @@ public class Pleroma } catch (JsonException) { - //Not an error + //Not a simple error } try @@ -96,8 +96,10 @@ public class Pleroma } catch (JsonException) { - //Not an error + //Not an aggregate error } + + throw new HttpRequestException(text); } if (res.StatusCode is >= (HttpStatusCode)200 and < (HttpStatusCode)300)