mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(apiv2): ignore exception caused by invalid user-provided JSON
return 400 bad request instead
This commit is contained in:
parent
a20276f6e6
commit
eb05cbf76c
1 changed files with 9 additions and 0 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue