-1

So far I have the following code to be used to check whether a LUIS JSON response contains a entity or not

public static class StatusHelper
{        
    public static bool EntityCheck(LuisResult result)
    {
        try
        {
            var statuscheck = result.Entities[0].Entity;
            return true;
        } catch (Exception)
        {
            return false;
        }
    }
}

And inside another file I used

if (StatusHelper.EntityCheck(LuisResult result)) 
{

//code

}
else 
{
    await context.PostAsync("No Entities");
}

In my bot emulator, if no entities were found, it would have the bot saying

No Entities

But on the dev.botframework.com website it would say

Sorry, my bot code is having an issue.

I'm not sure what's going on here

yfan183
  • 547
  • 2
  • 7
  • 20

1 Answers1

1

Why are you using an Exception throw for testing if there is a value? Can't you just check is your result and some entities in the array, then check if the 1st entity is not null like the following:

public static bool EntityCheck(LuisResult result)
{
    return (result.Entities.Count > 0 && result.Entities[0].Entity != null);
}
Nicolas R
  • 13,812
  • 2
  • 28
  • 57