diff --git a/Iceshrimp.Backend/Core/Federation/WebFinger/WebFingerService.cs b/Iceshrimp.Backend/Core/Federation/WebFinger/WebFingerService.cs index e14fc7f8..1c015f66 100644 --- a/Iceshrimp.Backend/Core/Federation/WebFinger/WebFingerService.cs +++ b/Iceshrimp.Backend/Core/Federation/WebFinger/WebFingerService.cs @@ -27,6 +27,8 @@ public class WebFingerService(HttpClient client, HttpRequestService httpRqSvc) { var req = httpRqSvc.Get(webFingerUrl, ["application/jrd+json", "application/json"]); var res = await client.SendAsync(req); + if (res.StatusCode == HttpStatusCode.Gone) + throw GracefulException.Accepted("The remote user no longer exists."); if (!res.IsSuccessStatusCode) return null; if (res.Content.Headers.ContentType?.MediaType is not "application/jrd+json" and not "application/json") diff --git a/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs b/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs index bad3d2a4..9c948150 100644 --- a/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs +++ b/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs @@ -25,6 +25,12 @@ public class ErrorHandlerMiddleware(IOptions options, IL var verbosity = options.Value.ExceptionVerbosity; if (e is GracefulException ce) { + if (ce.StatusCode == HttpStatusCode.Accepted) { + ctx.Response.StatusCode = (int)ce.StatusCode; + await ctx.Response.CompleteAsync(); + return; + } + if (verbosity > ExceptionVerbosity.Basic && ce.OverrideBasic) verbosity = ExceptionVerbosity.Basic; @@ -112,6 +118,13 @@ public class GracefulException( return new GracefulException(HttpStatusCode.MisdirectedRequest, HttpStatusCode.MisdirectedRequest.ToString(), "This server is not configured to respond to this request.", null, true, true); } + + /// + /// This is intended for cases where no error occured, but the request needs to be aborted early (e.g. WebFinger returning 410 Gone) + /// + public static GracefulException Accepted(string message) { + return new GracefulException(HttpStatusCode.Accepted, message); + } } public enum ExceptionVerbosity {