fix: asp.net doesn't automatically complete the response writer

This commit is contained in:
spiral 2021-11-03 23:27:44 -04:00
parent e1a5310a3a
commit bdb6b61903
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -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;
}
else
{
var err = (PKError)exc.Error;
ctx.Response.StatusCode = err.ResponseCode;
var json = JsonConvert.SerializeObject(err.ToJson());
await ctx.Response.WriteAsync(json);
}
await ctx.Response.CompleteAsync();
}));
app.UseMiddleware<AuthorizationTokenHandlerMiddleware>();