From bdb6b61903954e4dad1e996acc9f7b3feecedbd0 Mon Sep 17 00:00:00 2001 From: spiral Date: Wed, 3 Nov 2021 23:27:44 -0400 Subject: [PATCH] fix: asp.net doesn't automatically complete the response writer --- PluralKit.API/Startup.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/PluralKit.API/Startup.cs b/PluralKit.API/Startup.cs index 1a01356c..34e3a0e3 100644 --- a/PluralKit.API/Startup.cs +++ b/PluralKit.API/Startup.cs @@ -148,30 +148,31 @@ namespace PluralKit.API { ctx.Response.StatusCode = 400; await ctx.Response.WriteAsync("{\"message\":\"400: Bad Request\",\"code\":0}"); - return; } - if (exc.Error is not PKError) + else if (exc.Error is not PKError) { ctx.Response.StatusCode = 500; await ctx.Response.WriteAsync("{\"message\":\"500: Internal Server Error\",\"code\":0}"); - return; } // for some reason, if we don't specifically cast to ModelParseError, it uses the base's ToJson method - if (exc.Error is ModelParseError fe) + else if (exc.Error is ModelParseError fe) { ctx.Response.StatusCode = fe.ResponseCode; await ctx.Response.WriteAsync(JsonConvert.SerializeObject(fe.ToJson())); - - return; } - var err = (PKError)exc.Error; - ctx.Response.StatusCode = err.ResponseCode; + else + { + var err = (PKError)exc.Error; + ctx.Response.StatusCode = err.ResponseCode; - var json = JsonConvert.SerializeObject(err.ToJson()); - await ctx.Response.WriteAsync(json); + var json = JsonConvert.SerializeObject(err.ToJson()); + await ctx.Response.WriteAsync(json); + } + + await ctx.Response.CompleteAsync(); })); app.UseMiddleware();