Skip to content

Commit

Permalink
Streaming: Surface exceptions like other paths to allow error handlin…
Browse files Browse the repository at this point in the history
…g in upper layers. (#5803) (#5804)

* Streaming: Surface exceptions like other paths to allow error handling in upper layers.

* Fix typo
  • Loading branch information
carlosscastro committed Jul 23, 2021
1 parent ffb0d5f commit 82b7d37
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,28 +403,24 @@ public async Task<ResourceResponse> SendActivityAsync(Activity activity, Cancell
}
}

try
if (!_serverIsConnected)
{
if (!_serverIsConnected)
{
throw new InvalidOperationException("Error while attempting to send: Streaming transport is disconnected.");
}
throw new InvalidOperationException("Error while attempting to send: Streaming transport is disconnected.");
}

var serverResponse = await _server.SendAsync(request, cancellationToken).ConfigureAwait(false);
// Attempt to send the request. If send fails, we let the original exception get thrown so that the
// upper layers can handle it and trigger OnError. This is consistent with error handling in http and proactive
// paths, making all 3 paths consistent in terms of error handling.
var serverResponse = await _server.SendAsync(request, cancellationToken).ConfigureAwait(false);

if (serverResponse.StatusCode == (int)HttpStatusCode.OK)
{
return serverResponse.ReadBodyAsJson<ResourceResponse>();
}
if (serverResponse.StatusCode == (int)HttpStatusCode.OK)
{
return serverResponse.ReadBodyAsJson<ResourceResponse>();
}
#pragma warning disable CA1031 // Do not catch general exception types (this should probably be addressed later, but for now we just log the error and continue the execution)
catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
else
{
_logger.LogError(ex.Message);
throw new Exception($"Failed to send request through streaming transport. Status code: {serverResponse.StatusCode}.");
}

return null;
}

/// <summary>
Expand Down

0 comments on commit 82b7d37

Please sign in to comment.