diff --git a/src/Infrastructure/BotSharp.Core.Crontab/Functions/TaskWaitFn.cs b/src/Infrastructure/BotSharp.Core.Crontab/Functions/TaskWaitFn.cs index b4e63a76..0fb68dc9 100644 --- a/src/Infrastructure/BotSharp.Core.Crontab/Functions/TaskWaitFn.cs +++ b/src/Infrastructure/BotSharp.Core.Crontab/Functions/TaskWaitFn.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace BotSharp.Core.Crontab.Functions; @@ -22,12 +23,17 @@ public class TaskWaitFn : IFunctionCallback try { var args = JsonSerializer.Deserialize(message.FunctionArgs); - if (args != null || args.DelayTime > 0) + if (args != null && args.DelayTime > 0) { await Task.Delay(args.DelayTime * 1000); } message.Content = "wait task completed"; } + catch (JsonException jsonEx) + { + message.Content = "Invalid function arguments format."; + _logger.LogError(jsonEx, "Json deserialization failed."); + } catch (Exception ex) { message.Content = "Unable to perform delay task";