-
Notifications
You must be signed in to change notification settings - Fork 67
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
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
HttpRepl/src/Microsoft.Repl/Commanding/DefaultCommandDispatcher.cs
Lines 119 to 122 in feb5c12
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 |
There was a problem hiding this comment.
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... 😝
There was a problem hiding this comment.
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!
Resolves #304.
Handle some of the "expected" exceptions in
BaseHttpCommand
when executing HTTP Requests viaHttpClient
.