0

I have the following health check / status method in my Azure function app: (v4)

public static class HealthStatus
{
    [FunctionName("HealthStatus")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "health/status")] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        string qn = req.Query["qn"];

        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);
        qn = qn ?? data?.name;

        string responseMessage = string.IsNullOrEmpty(qn )
            ? "qn : All. Status OK"
            : $"qn : {qn }. Status OK";

        return new OkObjectResult(responseMessage);
    }
}

Locally when I run a GET on this, i get the "All. Status OK" method. Upstream, after I publish to azure, when i use the "code & test" option in azure to try to run this function, it only works if I GET with a query string parameter called qn. Otherwise, instead of a 200 OK, I get a "500 internal server error". The logs show this error:

 2022-06-14T17:49:36.042 [Information] C# HTTP trigger function processed a request.
2022-06-14T17:49:36.150 [Error] Executed 'HealthStatus' (Failed, Id=asdf-e859-asdf-asdf-asdf123123, Duration=78ms)'string' does not contain a definition for 'name'

Any tips as to why the results are different and how I can fix would be appreciated.

1 Answer 1

0

When you call it with the qn query parameter, this line returns a value:

  string qn = req.Query["qn"];

Then this line, uses the value in qn:

 qn = qn ?? data?.name;

When you do not call with qn, it uses data?.name

data comes from the request body and does not have a property name

Sign up to request clarification or add additional context in comments.

2 Comments

ok but locally when I run it i just do a get with no query string and no body... and it just works.
It may be that the contents of req.body is different depending on how it is tested

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.