feat(apiv2): ignore exception caused by invalid user-provided JSON
return 400 bad request instead
This commit is contained in:
parent
a20276f6e6
commit
eb05cbf76c
@ -133,6 +133,15 @@ namespace PluralKit.API
|
|||||||
app.UseExceptionHandler(handler => handler.Run(async ctx =>
|
app.UseExceptionHandler(handler => handler.Run(async ctx =>
|
||||||
{
|
{
|
||||||
var exc = ctx.Features.Get<IExceptionHandlerPathFeature>();
|
var exc = ctx.Features.Get<IExceptionHandlerPathFeature>();
|
||||||
|
|
||||||
|
// handle common ISEs that are generated by invalid user input
|
||||||
|
if (exc.Error is InvalidCastException && exc.Error.Message.Contains("Newtonsoft.Json"))
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = 400;
|
||||||
|
await ctx.Response.WriteAsync("{\"message\":\"400: Bad Request\",\"code\":0}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (exc.Error is not PKError)
|
if (exc.Error is not PKError)
|
||||||
{
|
{
|
||||||
ctx.Response.StatusCode = 500;
|
ctx.Response.StatusCode = 500;
|
||||||
|
Loading…
Reference in New Issue
Block a user