azureazure-functionscsx

How can I manually mark an invocation as Failure in an Azure Function?


I have tried many things but the only way I can force AzFn to understand the invocation has failed, is to throw an exception and not handle it. So, if I return an HttpResponseException, AzFn will consider the invocation as a success. That feels wrong.

catch (Exception ex)
    {
        logger.Error($"{nameof(ex)}: {ex.Message}", ex);
        response = req.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message, ex);

    }

This should produce an invocation marked as fail but it doesn't.


Solution

  • Any exception thrown from your function will mark the function as failed. In your code above you're swallowing the exception, so we consider it successful. If you instead rethrow the exception, the function will be marked as failed. We'll automatically return a 500 in such cases on your behalf.

    We don't look at the HttpStatusCode you return to determine if the function is successful, only whether the function ran successfully to completion w/o exception. If your function is able to return a response, it is successful from our point of view.