Forum Discussion

amatthews-yakchat's avatar
amatthews-yakchat
Copper Contributor
May 25, 2022

Operation returned an invalid status code 'Forbidden'/'NotFound'

I am having a recurring problem with our Bot in Teams that I am struggling to find a root cause and fix for.

 

We have a bot that has been developed using the C# Bot Framework SDK Version 4 and .NET Core 3.1 that is installed via Teams. There is an issue that is recurring in our Application Insights that I am struggling to figure out. There are multiple exceptions that happen intermittently with the message "Operation returned an invalid status code 'Forbidden'" or "Operation returned an invalid status code 'NotFound'". The only commonality with all these errors are that they happen in the same area of the code.

 

The bot we have implemented makes use of a waterfall dialog system to handle the authentication and login for users and handle incoming messages once authenticated. The errors always occur when the bot is trying to move on to the next dialog step after completing the OAuthPrompt step, as shown in the screenshot below.

 

I have searched to try and find why this is happening or even a solution to this issue and although I have found similar problems and have tried their solutions, they have not been able to fix this error.

 

Has anyone else had an issue similar to this, or know what the problem could be?

    • Sayali-MSFT's avatar
      Sayali-MSFT
      Icon for Microsoft rankMicrosoft
      amatthews-yakchat-We are not able to reproduce the scenario.Could you please share the any referred sample or repro steps, So that we can investigate it from our end?
      • amatthews-yakchat's avatar
        amatthews-yakchat
        Copper Contributor

        Sayali-MSFT Apologies for the delayed response, I was on vacation for the last week. I'm not sure what the repro steps are for this issue as it happens intermittently and looking at the telemetry there doesn't seem to be any common ground or any cases where it happens 100% of the time.

         

        I've included the area of code where I think the error originates from below. Like I mentioned in my original post, we are using the WaterfallDialog approach with this bot and this is one of the steps, the error seems to be thrown when moving away from this step to the next.

         

        private async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
        	try
        	{
        		UserProfile Profile = await this._stateAccessor.GetAsync(stepContext.Context, () => new UserProfile());
        
        		if (String.IsNullOrWhiteSpace(stepContext.Context.Activity.Text))
        		{
        			if (!String.IsNullOrWhiteSpace(Profile.CachedMessage))
        			{
        				stepContext.Context.Activity.Text = Profile.CachedMessage;
        				Profile.CachedMessage = String.Empty;
        			}
        		}
        
        		return await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken);
        	}
        	catch (Exception exc)
        	{
        		Dictionary<String, String> Properties = new Dictionary<String, String>();
        		Properties.Add("Class", "MainDialog");
        		Properties.Add("Method", "PromptStepAsync");
        
        		AppInsightsHelper.LogException(exc, Properties, stepContext.Context);
        
        		await stepContext.Context.SendActivityAsync(BotResponse.ErrorMessage_GenericErrorResponse);
        		return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
        	}
        }

         

Resources