Skip to content

Return specific status code for azure function with input binding event grid trigger #874

@imbachb

Description

@imbachb

What language does your question apply to? (e.g., C#, JavaScript, Java, All)

Python

Question

In my application I have the issue that a failing event grid triggered azure function is continually triggered because of the event grid retry policy.
As we can read in Azure Event Grid - Delivery And Retry, if the azure function fails with error code 500 the event grid continuously retries to deliver the event to the azure function.

In most cases this is fine, but in a specific case I would like to catch the specific exception and return the function with a status code 400, as this would stop the event grid from retrying to deliver the event.

Is this possible, or am I forced catch the exception and return the function normally, resulting in a status code of 200? I would prefer to mark this trigger as failing.

What I tried:
Add an HTTP output binding to my function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

However, when I return the azure function with
return func.HttpResponse(e, status_code=400)
the following casting exception is thrown later:
System.Private.CoreLib: Exception while executing function: Functions.ImageUploadTrigger. Microsoft.Azure.WebJobs.Script: Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Microsoft.AspNetCore.Http.HttpRequest'.

It seems an "in" "eventGridTrigger" is not compatible with an "http" "out" binding.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions