Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Allow to access Function result #2792

Open pinggi opened 2 years ago

pinggi commented 2 years ago

I would like to get Azure Function result in FunctionInvocationFilterAttribute to be able to check whether the returned value was successful (200 OK or an error status in case of IActionResult).

The result is returned from InvokeAsync in FunctionExecutor but is not passed further to the FunctionExecutedContext. Instead hardcoded true value is passed.

public class AuditAttribute: FunctionInvocationFilterAttribute
{
  public override Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
  {
    if (!(executedContext.Arguments.Values.FirstOrDefault(argument => argument is HttpRequest) is HttpRequest httpRequest))
    {
      throw new ArgumentException("Audit attribute requires azure functions with HttpRequest parameter");
    }

    if (!(httpRequest.HttpContext.Items["audit"] is Audit audit))
    {
        throw new ArgumentException("Audit object is missing in HttpContext");
    }

    audit.FunctionResult = executedContext.FunctionResult.Succeeded; // Here I'd I like to get the result not just `true`
  }
}
v-bbalaiagar commented 2 years ago

Hi @pinggi, Flagging this issue as a feature enhancement request.