Skip to content

Commit

Permalink
idp handle host unknown (#3192)
Browse files Browse the repository at this point in the history
when host is not known, handle exception so we give back a better error message
  • Loading branch information
esmadau authored Nov 13, 2023
1 parent b58c67f commit 54289aa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,14 @@ private async Task<T> ExecuteAsync<T>(
_logger.LogError(ex, message: "Access to storage account failed with ErrorCode: {ErrorCode}", ex.ErrorCode);
throw new DataStoreRequestFailedException(ex, _blobClient.IsExternal);
}
catch (AggregateException ex) when (_blobClient.IsExternal && ex.InnerException is RequestFailedException)
{
var innerEx = ex.InnerException as RequestFailedException;
_logger.LogError(innerEx,
message: "Access to external storage account failed with ErrorCode: {ErrorCode}",
innerEx.ErrorCode);
throw new DataStoreRequestFailedException(innerEx, _blobClient.IsExternal);
}
catch (Exception ex)
{
_logger.LogError(ex, "Access to storage account failed");
Expand Down
18 changes: 18 additions & 0 deletions src/Microsoft.Health.Dicom.Core/DicomCoreResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Microsoft.Health.Dicom.Core/DicomCoreResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ For details on valid range queries, please refer to Search Matching section in C
<data name="ExternalDataStoreOperationFailed" xml:space="preserve">
<value>Error occurred during an operation on the configured storage account. Use the https://go.microsoft.com/fwlink/?linkid=2251550 to troubleshoot the issue. Received the following error code: {0}</value>
</data>
<data name="ExternalDataStoreHostIsUnknown" xml:space="preserve">
<value>Error occurred during an operation on the configured storage account. Use the https://go.microsoft.com/fwlink/?linkid=2251550 to troubleshoot the issue. No such host is known.</value>
</data>
<data name="ExternalDataStoreOperationFailedUnknownIssue" xml:space="preserve">
<value>Error occurred during an operation on the configured storage account. Use the https://go.microsoft.com/fwlink/?linkid=2251550 to troubleshoot the issue.</value>
</data>
<data name="ExternalDataStoreBlobModified" xml:space="preserve">
<value>Received the following error code from blob storage account: {0}. Can not perform operation '{1}' because the blob '{2}' with eTag '{3}' has been modified or deleted by another process. Use the https://go.microsoft.com/fwlink/?linkid=2251550 to troubleshoot the issue.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;
using System.Globalization;
using Azure;

Expand All @@ -17,10 +18,33 @@ public class DataStoreRequestFailedException : ConditionalExternalException
public DataStoreRequestFailedException(RequestFailedException ex, bool isExternal = false)
: base(
(isExternal ?
string.Format(CultureInfo.InvariantCulture, DicomCoreResource.ExternalDataStoreOperationFailed, ex?.ErrorCode)
getFormattedExternalStoreMessage(ex)
: DicomCoreResource.DataStoreOperationFailed),
ex,
isExternal)
{
}

private static string getFormattedExternalStoreMessage(RequestFailedException ex)
{
return !string.IsNullOrEmpty(ex?.ErrorCode)
? string.Format(
CultureInfo.InvariantCulture,
DicomCoreResource.ExternalDataStoreOperationFailed,
ex?.ErrorCode)
: GetFormattedExternalStoreMessageWithoutErrorCode(ex)
;
}

private static string GetFormattedExternalStoreMessageWithoutErrorCode(RequestFailedException ex)
{
if (ex.Message.Contains("No such host is known", StringComparison.OrdinalIgnoreCase))
{
return DicomCoreResource.ExternalDataStoreHostIsUnknown;
}

// if we do not have an error code and internal message is not "host not known", we are not familiar with the issue
// we can't just give back the exception message as it may contain sensitive information
return DicomCoreResource.ExternalDataStoreOperationFailedUnknownIssue;
}
}

0 comments on commit 54289aa

Please sign in to comment.