Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 366
imbageek Avatar asked Mar 14 '17 09:03

imbageek


1 Answers

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.

like image 131
mathewc Avatar answered Oct 23 '22 12:10

mathewc