Skip to content

Commit

Permalink
Avoid null reference exception
Browse files Browse the repository at this point in the history
Fix #15419
  • Loading branch information
MikeAlhayek committed Feb 28, 2024
1 parent f35c8eb commit 06f61e0
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public WorkflowTypeStep(IWorkflowTypeStore workflowTypeStore,
_workflowTypeStore = workflowTypeStore;
_securityTokenService = securityTokenService;
_jsonSerializerOptions = jsonSerializerOptions.Value;
_urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
// When an instance of this class is created outside of a controller's action, the ActionContext is null.
if (actionContextAccessor.ActionContext != null)
{
_urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
}
}

public async Task ExecuteAsync(RecipeExecutionContext context)
Expand All @@ -49,12 +53,15 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
{
var workflow = token.ToObject<WorkflowType>(_jsonSerializerOptions);

foreach (var activity in workflow.Activities.Where(a => a.Name == nameof(HttpRequestEvent)))
if (_urlHelper is not null)
{
var tokenLifeSpan = activity.Properties["TokenLifeSpan"];
if (tokenLifeSpan != null)
foreach (var activity in workflow.Activities.Where(a => a.Name == nameof(HttpRequestEvent)))
{
activity.Properties["Url"] = ReGenerateHttpRequestEventUrl(workflow, activity, tokenLifeSpan.ToObject<int>());
var tokenLifeSpan = activity.Properties["TokenLifeSpan"];
if (tokenLifeSpan != null)
{
activity.Properties["Url"] = ReGenerateHttpRequestEventUrl(workflow, activity, tokenLifeSpan.ToObject<int>());
}
}
}

Expand Down

0 comments on commit 06f61e0

Please sign in to comment.