Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix http adapter errors #2593

Merged
merged 1 commit into from
Sep 24, 2019
Merged

fix http adapter errors #2593

merged 1 commit into from
Sep 24, 2019

Conversation

johnataylor
Copy link
Member

Both integration implementations return BadRequest when called with something other than an Activity.

An Activity being something that can be serialized into an Activity with a Type. All fields other than Type are optional. Technically at any one release, Type is restricted in what values it can take, however, this is not practical to constrain at this level (it is handled in the ActivityHandler layer.)

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 80284

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 5 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.2%) to 81.21%

Files with Coverage Reduction New Missed Lines %
/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/HttpHelper.cs 2 93.94%
/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/BotFrameworkHttpAdapter.cs 3 75.0%
Totals Coverage Status
Change from base Build 80267: 0.2%
Covered Lines: 3812
Relevant Lines: 4694

💛 - Coveralls

@fuselabs
Copy link
Collaborator

✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.Luis.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.AI.QnA.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.ApplicationInsights.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Azure.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.Dialogs.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Builder.TemplateManager.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Configuration.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Connector.dll compared against version 4.3.1
✔️ No Binary Compatibility issues for Microsoft.Bot.Schema.dll compared against version 4.3.1

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments around logging. Consider adding those, then merging.

@@ -62,6 +62,12 @@ public async Task ProcessAsync(HttpRequest httpRequest, HttpResponse httpRespons
// deserialize the incoming Activity
var activity = HttpHelper.ReadRequest(httpRequest);

if (string.IsNullOrEmpty(activity?.Type))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a detailed comment here, as the behavior is non-obvious.

{
activity = BotMessageSerializer.Deserialize<Activity>(bodyReader);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should log, using our infrastructure so it ends up in the right place. I can see that being important to debugging sessions by the Supportability team.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be logged at the HTTP level. This change uses the correct HTTP error code.

@@ -46,6 +46,12 @@ public async Task ProcessAsync(HttpRequestMessage httpRequest, HttpResponseMessa
// deserialize the incoming Activity
var activity = await HttpHelper.ReadRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

if (string.IsNullOrEmpty(activity?.Type))
{
httpResponse.StatusCode = HttpStatusCode.BadRequest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider logging here as well.

if (string.IsNullOrEmpty(activity?.Type))
{
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider logging something. That way when support requests come in complaining "My Bot is returning Bad Request,and I'm not sure why" the truth is in the log files.

var activity = await request.Content.ReadAsAsync<Activity>(BotMessageMediaTypeFormatters, cancellationToken).ConfigureAwait(false);
return activity;
}
catch (UnsupportedMediaTypeException)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging

}
catch (JsonException)
{
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto point about logging - look at the HTTP traffic for the result. Bad Request is exactly that. Its not a server error - at the application level the client should log this. This makes HTTP logs more meaningful.

@@ -142,6 +142,32 @@ public void ConstructorWithConfiguration()
Assert.Equal("botOpenIdMetadata", GovernmentChannelValidation.OpenIdMetadataUrl);
}

[Fact]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful. I've got tears of joy.

This really is quite slick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants