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;
|
namespace Uwaa.Pleroma;
|
||||||
|
|
||||||
public class PleromaException : Exception
|
public abstract class PleromaException : Exception
|
||||||
|
{
|
||||||
|
public override string ToString() => Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PleromaSimpleException : PleromaException
|
||||||
{
|
{
|
||||||
[JsonPropertyName("error")]
|
[JsonPropertyName("error")]
|
||||||
public string Text { get; set; } = null!;
|
public string Text { get; set; } = null!;
|
||||||
|
|
||||||
public override string Message => Text;
|
public override string Message => Text;
|
||||||
|
|
||||||
public override string ToString() => Message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PleromaAggregateException : Exception
|
public class PleromaAggregateException : PleromaException
|
||||||
{
|
{
|
||||||
[JsonPropertyName("errors")]
|
[JsonPropertyName("errors")]
|
||||||
public PleromaInnerException[] Text { get; set; } = null!;
|
public PleromaInnerException[] Text { get; set; } = null!;
|
||||||
|
|
||||||
public override string Message => string.Join("\n", (object?[])Text);
|
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")]
|
[JsonPropertyName("detail")]
|
||||||
public string Text { get; set; } = null!;
|
public string Text { get; set; } = null!;
|
||||||
|
|
||||||
public override string Message => Text;
|
public override string Message => Text;
|
||||||
|
|
||||||
public override string ToString() => Message;
|
|
||||||
}
|
}
|
|
@ -69,7 +69,7 @@ public class Pleroma
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PleromaException? err = JsonSerializer.Deserialize<PleromaException>(text, SerializerOptions);
|
PleromaSimpleException? err = JsonSerializer.Deserialize<PleromaSimpleException>(text, SerializerOptions);
|
||||||
if (err != null && err.Text != null)
|
if (err != null && err.Text != null)
|
||||||
{
|
{
|
||||||
if (err.Text == "Throttled")
|
if (err.Text == "Throttled")
|
||||||
|
@ -85,7 +85,7 @@ public class Pleroma
|
||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
//Not an error
|
//Not a simple error
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -96,8 +96,10 @@ public class Pleroma
|
||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
//Not an error
|
//Not an aggregate error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new HttpRequestException(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.StatusCode is >= (HttpStatusCode)200 and < (HttpStatusCode)300)
|
if (res.StatusCode is >= (HttpStatusCode)200 and < (HttpStatusCode)300)
|
||||||
|
|
Loading…
Reference in a new issue