Azure / Azure/azure-functions-nodejs-library

Cancel Function execution from a Hook

Open
#169 0 comments 0 reactions 0 assignees View on GitHub
area:nodejs-functions enhancement hooks P2
Dominant language
TypeScript
Stars
70
Forks
35
Avg merge
4d 18h
Merged PRs (30d)
6

Description

As touched on in Azure/azure-functions-nodejs-worker#664 a scenario for a pre/post invocation hook, when used like middleware, would be to cancel/abort the execution of the Function, and even provide an alternative `out` binding.

Here's a scenario:

> You have a REST API using Azure Functions to handle the user interactions. To ensure that you don't rely on the client to provide valid data you want to perform server validation based off a validation schema. As this is a REST API you can infer the object you're validating from the URL of the request, so rather than having each function perform its own validation you want a piece of middleware to do it.
> If the validation passes, then you want to call to "original" Function so that data is persisted/etc. but if it fails validation you want to respond with a `400 Bad Request` and provide the error messages.

Currently there is no way to say "stop execution" or "execute this Function instead" from within a hook, without overriding `functionCallback` property of the `HookContext`, but that's probably not recommended.

From a billing/usage standpoint, we should still treat the Function as "executed", even if there is an early abort provided, as you've still executed something in context of that Function invocation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.