fix(apiv2): correctly parse timestamp in SwitchPatch
This commit is contained in:
parent
098d804344
commit
431f7e8931
@ -163,11 +163,13 @@ namespace PluralKit.API
|
|||||||
if (!Guid.TryParse(switchRef, out var switchId))
|
if (!Guid.TryParse(switchRef, out var switchId))
|
||||||
throw APIErrors.InvalidSwitchId;
|
throw APIErrors.InvalidSwitchId;
|
||||||
|
|
||||||
var value = data.Value<Instant>("timestamp");
|
var valueStr = data.Value<string>("timestamp").NullIfEmpty();
|
||||||
if (value == null)
|
if (valueStr == null)
|
||||||
// todo
|
// todo
|
||||||
throw APIErrors.GenericBadRequest;
|
throw APIErrors.GenericBadRequest;
|
||||||
|
|
||||||
|
var value = Instant.FromDateTimeOffset(DateTime.Parse(valueStr).ToUniversalTime());
|
||||||
|
|
||||||
var system = await ResolveSystem("@me");
|
var system = await ResolveSystem("@me");
|
||||||
if (system == null)
|
if (system == null)
|
||||||
throw APIErrors.SystemNotFound;
|
throw APIErrors.SystemNotFound;
|
||||||
|
@ -140,7 +140,10 @@ namespace PluralKit.API
|
|||||||
var exc = ctx.Features.Get<IExceptionHandlerPathFeature>();
|
var exc = ctx.Features.Get<IExceptionHandlerPathFeature>();
|
||||||
|
|
||||||
// handle common ISEs that are generated by invalid user input
|
// 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;
|
ctx.Response.StatusCode = 400;
|
||||||
await ctx.Response.WriteAsync("{\"message\":\"400: Bad Request\",\"code\":0}");
|
await ctx.Response.WriteAsync("{\"message\":\"400: Bad Request\",\"code\":0}");
|
||||||
|
Loading…
Reference in New Issue
Block a user