Skip to content

Commit

Permalink
code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Jul 12, 2021
1 parent 0d5417f commit 139ca9c
Showing 1 changed file with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public SslClientAuthenticationOptions SslOptions

protected internal override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException ();
throw new PlatformNotSupportedException();
}

protected internal override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -323,22 +323,27 @@ protected internal override async Task<HttpResponseMessage> SendAsync(HttpReques
return httpResponse;

}
catch (OperationCanceledException oce ) when (cancellationToken.IsCancellationRequested)
catch (OperationCanceledException oce) when (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(oce, cancellationToken);
}
catch (JSException jse)
{
if (jse.Message.StartsWith("AbortError"))
{
throw CancellationHelper.CreateOperationCanceledException(jse, CancellationToken.None);
}
if (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(jse, cancellationToken);
}
throw new HttpRequestException(jse.Message, jse);
throw TranslateJSException(jse, cancellationToken);
}
}

private static Exception TranslateJSException(JSException jse, CancellationToken cancellationToken)
{
if (jse.Message.StartsWith("AbortError", StringComparison.Ordinal))
{
return CancellationHelper.CreateOperationCanceledException(jse, CancellationToken.None);
}
if (cancellationToken.IsCancellationRequested)
{
return CancellationHelper.CreateOperationCanceledException(jse, cancellationToken);
}
return new HttpRequestException(jse.Message, jse);
}

private sealed class WasmFetchResponse : IDisposable
Expand Down Expand Up @@ -415,11 +420,7 @@ private async Task<byte[]> GetResponseData(CancellationToken cancellationToken)
}
catch (JSException jse)
{
if (jse.Message.StartsWith("AbortError"))
{
throw CancellationHelper.CreateOperationCanceledException(jse, cancellationToken);
}
throw new HttpRequestException(jse.Message, jse);
throw TranslateJSException(jse, cancellationToken);
}

return _data;
Expand Down Expand Up @@ -503,21 +504,13 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
_reader = (JSObject)body.Invoke("getReader");
}
}
catch (OperationCanceledException oce ) when (cancellationToken.IsCancellationRequested)
catch (OperationCanceledException oce) when (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(oce, cancellationToken);
}
catch (JSException jse)
{
if (jse.Message.StartsWith("AbortError"))
{
throw CancellationHelper.CreateOperationCanceledException(jse, CancellationToken.None);
}
if (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(jse, cancellationToken);
}
throw new HttpRequestException(jse.Message, jse);
throw TranslateJSException(jse, cancellationToken);
}
}

Expand Down Expand Up @@ -547,21 +540,13 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer, Cancellation
_bufferedBytes = binValue.ToArray();
}
}
catch (OperationCanceledException oce ) when (cancellationToken.IsCancellationRequested)
catch (OperationCanceledException oce) when (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(oce, cancellationToken);
}
catch (JSException jse)
{
if (jse.Message.StartsWith("AbortError"))
{
throw CancellationHelper.CreateOperationCanceledException(jse, CancellationToken.None);
}
if (cancellationToken.IsCancellationRequested)
{
throw CancellationHelper.CreateOperationCanceledException(jse, cancellationToken);
}
throw new HttpRequestException(jse.Message, jse);
throw TranslateJSException(jse, cancellationToken);
}

return ReadBuffered();
Expand Down

0 comments on commit 139ca9c

Please sign in to comment.