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

Handle HTTP Request errors in BaseHttpCommand #419

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

tlmii
Copy link
Member

@tlmii tlmii commented Oct 27, 2020

Resolves #304.

Handle some of the "expected" exceptions in BaseHttpCommand when executing HTTP Requests via HttpClient.

@tlmii tlmii requested review from jimmylewis and bzhu94 October 27, 2020 22:53
Copy link

@bzhu94 bzhu94 left a comment

Choose a reason for hiding this comment

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

Looks good!

@@ -165,8 +165,21 @@ protected override async Task ExecuteAsync(IShellState shellState, HttpState pro
string headersTarget = responseHeadersFileOption?.Text ?? responseFileOption?.Text;
string bodyTarget = responseBodyFileOption?.Text ?? responseFileOption?.Text;

HttpResponseMessage response = await programState.Client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
await HandleResponseAsync(programState, commandInput, shellState.ConsoleManager, response, programState.EchoRequest, headersTarget, bodyTarget, cancellationToken).ConfigureAwait(false);
Copy link

Choose a reason for hiding this comment

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

Just curious, if nothing was catching exceptions here, what thing did catch them to allow the exception stack to show in the console?

Copy link
Member Author

Choose a reason for hiding this comment

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

Further up the command execution pipeline:

catch (Exception ex)
{
shellState.ConsoleManager.Error.WriteLine(ex.ToString().Bold().Red());
}

catch (OperationCanceledException)
{
// We just want to eat this exception because the cancellation actually occurs for the entire command,
// not just the HTTP Request. So the cancellation is handled further down the stack by inspecting
Copy link

Choose a reason for hiding this comment

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

So before this fix the user would see a stacktrace anytime they canceled a command? That's not good... 😝

Copy link
Member Author

Choose a reason for hiding this comment

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

So before this fix the user would see a stacktrace anytime they canceled a command?

Depends on the command. But if there was an HTTP request in flight, yes.

that's not good... 😝

Nope!

@tlmii tlmii merged commit 62713b0 into dotnet:master Nov 2, 2020
@tlmii tlmii deleted the dev/handle-exceptions-on-http-calls branch November 2, 2020 08:10
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.

httprepl nice idea, but why are error messages like fail to connect shown as stacktraces?
2 participants