diff --git a/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Import/GetImportRequestHandlerTests.cs b/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Import/GetImportRequestHandlerTests.cs index 058601c674..5d5b602e5d 100644 --- a/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Import/GetImportRequestHandlerTests.cs +++ b/src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Import/GetImportRequestHandlerTests.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Net; using System.Threading; @@ -65,12 +66,14 @@ public async Task WhenGettingFailedJob_ThenExecptionIsTrownWithCorrectResponseCo { var coord = new JobInfo() { Status = JobStatus.Completed }; var workerResult = new ImportJobErrorResult() { ErrorMessage = "Error", HttpStatusCode = statusCode }; - var worker = new JobInfo() { Id = 1, Status = JobStatus.Failed, Result = JsonConvert.SerializeObject(workerResult) }; + var worker = new JobInfo() { Id = 1, Status = JobStatus.Failed, Result = JsonConvert.SerializeObject(workerResult), Definition = JsonConvert.SerializeObject(new ImportProcessingJobDefinition() { ResourceLocation = "http://xyz" }) }; + var definition = JsonConvert.DeserializeObject(worker.Definition); + var resourceLocation = new Uri(definition.ResourceLocation); var ofe = await Assert.ThrowsAsync(() => SetupAndExecuteGetBulkImportJobByIdAsync(coord, [worker])); Assert.Equal(statusCode == 0 ? HttpStatusCode.InternalServerError : statusCode, ofe.ResponseStatusCode); - Assert.Equal(string.Format(Core.Resources.OperationFailed, OperationsConstants.Import, ofe.ResponseStatusCode == HttpStatusCode.InternalServerError ? HttpStatusCode.InternalServerError : "Error"), ofe.Message); + Assert.Equal(string.Format(Core.Resources.OperationFailedWithErrorFile, OperationsConstants.Import, ofe.ResponseStatusCode == HttpStatusCode.InternalServerError ? HttpStatusCode.InternalServerError : "Error", resourceLocation.OriginalString), ofe.Message); } [Fact] @@ -78,12 +81,14 @@ public async Task WhenGettingFailedJob_WithGenericException_ThenExecptionIsTrown { var coord = new JobInfo() { Status = JobStatus.Completed }; object workerResult = new { message = "Error", stackTrace = "Trace" }; - var worker = new JobInfo() { Id = 1, Status = JobStatus.Failed, Result = JsonConvert.SerializeObject(workerResult) }; + var worker = new JobInfo() { Id = 1, Status = JobStatus.Failed, Result = JsonConvert.SerializeObject(workerResult), Definition = JsonConvert.SerializeObject(new ImportProcessingJobDefinition() { ResourceLocation = "http://xyz" }) }; + var definition = JsonConvert.DeserializeObject(worker.Definition); + var resourceLocation = new Uri(definition.ResourceLocation); var ofe = await Assert.ThrowsAsync(() => SetupAndExecuteGetBulkImportJobByIdAsync(coord, [worker])); Assert.Equal(HttpStatusCode.InternalServerError, ofe.ResponseStatusCode); - Assert.Equal(string.Format(Core.Resources.OperationFailed, OperationsConstants.Import, HttpStatusCode.InternalServerError), ofe.Message); + Assert.Equal(string.Format(Core.Resources.OperationFailedWithErrorFile, OperationsConstants.Import, HttpStatusCode.InternalServerError, resourceLocation.OriginalString), ofe.Message); } [Fact] diff --git a/src/Microsoft.Health.Fhir.Core/Features/Operations/Import/GetImportRequestHandler.cs b/src/Microsoft.Health.Fhir.Core/Features/Operations/Import/GetImportRequestHandler.cs index d859613bb1..3333dc122d 100644 --- a/src/Microsoft.Health.Fhir.Core/Features/Operations/Import/GetImportRequestHandler.cs +++ b/src/Microsoft.Health.Fhir.Core/Features/Operations/Import/GetImportRequestHandler.cs @@ -88,14 +88,18 @@ public async Task Handle(GetImportRequest request, Cancellati { var failed = jobs.First(x => x.Status == JobStatus.Failed && !x.CancelRequested); var errorResult = JsonConvert.DeserializeObject(failed.Result); + var definition = JsonConvert.DeserializeObject(failed.Definition); if (errorResult.HttpStatusCode == 0) { errorResult.HttpStatusCode = HttpStatusCode.InternalServerError; } + var resourceLocation = new Uri(definition.ResourceLocation); + // hide error message for InternalServerError var failureReason = errorResult.HttpStatusCode == HttpStatusCode.InternalServerError ? HttpStatusCode.InternalServerError.ToString() : errorResult.ErrorMessage; - throw new OperationFailedException(string.Format(Core.Resources.OperationFailed, OperationsConstants.Import, failureReason), errorResult.HttpStatusCode); + + throw new OperationFailedException(string.Format(Core.Resources.OperationFailedWithErrorFile, OperationsConstants.Import, failureReason, resourceLocation.OriginalString), errorResult.HttpStatusCode); } else // no failures here { diff --git a/src/Microsoft.Health.Fhir.Core/Resources.Designer.cs b/src/Microsoft.Health.Fhir.Core/Resources.Designer.cs index 5f873578c1..df9bb67ff6 100644 --- a/src/Microsoft.Health.Fhir.Core/Resources.Designer.cs +++ b/src/Microsoft.Health.Fhir.Core/Resources.Designer.cs @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -987,6 +988,15 @@ internal static string OperationFailed { } } + /// + /// Looks up a localized string similar to {0} operation failed for reason: {1} ErrorFile: {2}. + /// + internal static string OperationFailedWithErrorFile { + get { + return ResourceManager.GetString("OperationFailedWithErrorFile", resourceCulture); + } + } + /// /// Looks up a localized string similar to OperationOutcome.Location is deprecated, please use OperationOutcome.Expression. /// diff --git a/src/Microsoft.Health.Fhir.Core/Resources.resx b/src/Microsoft.Health.Fhir.Core/Resources.resx index 4f5af5e210..71bc08122a 100644 --- a/src/Microsoft.Health.Fhir.Core/Resources.resx +++ b/src/Microsoft.Health.Fhir.Core/Resources.resx @@ -747,4 +747,7 @@ Unable to get an access token for '{0}'. - \ No newline at end of file + + {0} operation failed for reason: {1} ErrorFile: {2} + +