Azure / Azure/azure-functions-host
Exception filter at Function App level for http triggered azure functions
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
I’m looking to handle exceptions at a function app level for my http triggered azure functions similar to how it is done in dotnetcore apps with ‘ExceptionFilterAttribute’. My goal is to catch all uncaught exceptions in the application at a single place and prepare the http response for the error scenario. I see that there is ‘IFunctionExceptionFilter’ which has a method ‘OnExceptionAsync’. However I’m not sure how I can get the context in this method so that I can manipulate Response to provide the right error messages. Also I believe this can only be done at a function level and not at the function app level. I also came across the [ErrorHandler] attribute here. However I’m not sure how I can use it.
Any help with this will be great. Below is the code that works in asp.net core mvc. I want to achieve the same in azure functions
OnException method in ExceptionFilterAttribute
public override void OnException(ExceptionContext context)
{
Exception ex = context.Exception;
context.Result = ResponseHelper.GetErrorResponse(ex);
}
Get ErrorResponse method returns an object which implements IActionResult
Contributor guide
Research direction
The issue mentions IFunctionExceptionFilter.OnExceptionAsync and the ErrorHandler attribute; begin by tracing their documented usage and whether either exposes an HTTP response context at function-app scope. Done means a confirmed supported approach—or a clearly documented limitation—for handling uncaught HTTP-trigger exceptions centrally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100