pleroma: unify exceptions
This commit is contained in:
parent
b4052c6460
commit
79f15e0439
2 changed files with 14 additions and 11 deletions
|
@ -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;
|
||||
}
|
|
@ -69,7 +69,7 @@ public class Pleroma
|
|||
{
|
||||
try
|
||||
{
|
||||
PleromaException? err = JsonSerializer.Deserialize<PleromaException>(text, SerializerOptions);
|
||||
PleromaSimpleException? err = JsonSerializer.Deserialize<PleromaSimpleException>(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)
|
||||
|
|
Loading…
Reference in a new issue