diff --git a/PluralKit.API/Controllers/v2/SwitchControllerV2.cs b/PluralKit.API/Controllers/v2/SwitchControllerV2.cs index 6623edbc..fe79760e 100644 --- a/PluralKit.API/Controllers/v2/SwitchControllerV2.cs +++ b/PluralKit.API/Controllers/v2/SwitchControllerV2.cs @@ -163,11 +163,13 @@ namespace PluralKit.API if (!Guid.TryParse(switchRef, out var switchId)) throw APIErrors.InvalidSwitchId; - var value = data.Value("timestamp"); - if (value == null) + var valueStr = data.Value("timestamp").NullIfEmpty(); + if (valueStr == null) // todo throw APIErrors.GenericBadRequest; + var value = Instant.FromDateTimeOffset(DateTime.Parse(valueStr).ToUniversalTime()); + var system = await ResolveSystem("@me"); if (system == null) throw APIErrors.SystemNotFound; diff --git a/PluralKit.API/Startup.cs b/PluralKit.API/Startup.cs index 04e6b434..c21b5a64 100644 --- a/PluralKit.API/Startup.cs +++ b/PluralKit.API/Startup.cs @@ -140,7 +140,10 @@ namespace PluralKit.API var exc = ctx.Features.Get(); // handle common ISEs that are generated by invalid user input - if (exc.Error is InvalidCastException && exc.Error.Message.Contains("Newtonsoft.Json")) + if ( + (exc.Error is InvalidCastException && exc.Error.Message.Contains("Newtonsoft.Json")) + || (exc.Error is FormatException && exc.Error.Message.Contains("was not recognized as a valid DateTime")) + ) { ctx.Response.StatusCode = 400; await ctx.Response.WriteAsync("{\"message\":\"400: Bad Request\",\"code\":0}");