generated from dotnet/new-repo
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from normj/support-amazon-ecr
- Loading branch information
Showing
3 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.NET.Build.Containers; | ||
|
||
/// <summary> | ||
/// A delegating handler that handles the special error handling needed for Amazon ECR. | ||
/// | ||
/// When pushing images to ECR if the target container repository does not exist ECR ends | ||
/// the connection causing an IOException with a generic "The response ended prematurely." | ||
/// error message. The handler catches the generic error and provides a more informed error | ||
/// message to let the user know they need to create the repository. | ||
/// </summary> | ||
public class AmazonECRMessageHandler : DelegatingHandler | ||
{ | ||
public AmazonECRMessageHandler(HttpMessageHandler innerHandler) : base(innerHandler) { } | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); | ||
} | ||
catch (HttpRequestException e) when (e.InnerException is IOException ioe && ioe.Message.Equals("The response ended prematurely.", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var message = "Request to Amazon Elastic Container Registry failed prematurely. This is often caused when the target repository does not exist in the registry."; | ||
throw new ContainerHttpException(message, request.RequestUri?.ToString(), null); | ||
} | ||
catch | ||
{ | ||
throw; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters