Skip to content

Commit

Permalink
Handle Reponse Error when building image (#590)
Browse files Browse the repository at this point in the history
* Handle Reponse Error when building image

* Change formatting

* Add a test

* Removed redundant async/await

* Fix failed unit tests affected by the new logic

* Improve event monitoring test
  • Loading branch information
aDisplayName authored Sep 23, 2022
1 parent 6c26b02 commit 4119439
Show file tree
Hide file tree
Showing 3 changed files with 326 additions and 295 deletions.
7 changes: 5 additions & 2 deletions src/Docker.DotNet/DockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,18 @@ await HandleIfErrorResponseAsync(response.StatusCode, response, errorHandlers)
.ConfigureAwait(false);
}

internal Task<HttpResponseMessage> MakeRequestForRawResponseAsync(
internal async Task<HttpResponseMessage> MakeRequestForRawResponseAsync(
HttpMethod method,
string path,
IQueryString queryString,
IRequestContent body,
IDictionary<string, string> headers,
CancellationToken token)
{
return PrivateMakeRequestAsync(SInfiniteTimeout, HttpCompletionOption.ResponseHeadersRead, method, path, queryString, headers, body, token);
var response = await PrivateMakeRequestAsync(SInfiniteTimeout, HttpCompletionOption.ResponseHeadersRead, method, path, queryString, headers, body, token).ConfigureAwait(false);
await HandleIfErrorResponseAsync(response.StatusCode, response)
.ConfigureAwait(false);
return response;
}

internal async Task<DockerApiStreamedResponse> MakeRequestForStreamedResponseAsync(
Expand Down
11 changes: 11 additions & 0 deletions test/Docker.DotNet.Tests/IImageOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ await _dockerClient.Images.TagImageAsync(
Assert.True(createImageTask.IsCanceled);
}

[Fact]
public Task CreateImageAsync_ErrorResponse_ThrowsDockerApiException()
{
return Assert.ThrowsAsync<DockerApiException>(() => _dockerClient.Images.CreateImageAsync(
new ImagesCreateParameters()
{
FromImage = "1.2.3.Apparently&this$is+not-a_valid%repository//name",
Tag = "ancient-one"
}, null, null));
}

[Fact]
public async Task DeleteImageAsync_RemovesImage()
{
Expand Down
Loading

0 comments on commit 4119439

Please sign in to comment.