Skip to content

Commit

Permalink
Merge pull request #704 from dlcs/feature/appetiserErrorReporting
Browse files Browse the repository at this point in the history
Improving error reporting from appetiser
  • Loading branch information
JackLewis-digirati authored Jan 11, 2024
2 parents 3e584e7 + 60ca350 commit 6c9b4b2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ public async Task ProcessImage_CreatesAndRemovesRequiredDirectories()
public async Task ProcessImage_False_IfImageProcessorCallFails()
{
// Arrange
httpHandler.SetResponse(new HttpResponseMessage(HttpStatusCode.InternalServerError));
var imageProcessorResponse = new AppetiserResponseErrorModel()
{
Message = "error",
Status = "some status"
};

var response = httpHandler.GetResponseMessage(JsonSerializer.Serialize(imageProcessorResponse, Settings),
HttpStatusCode.InternalServerError);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

httpHandler.SetResponse(response);
var context = GetIngestionContext();

// Act
Expand All @@ -93,6 +103,7 @@ public async Task ProcessImage_False_IfImageProcessorCallFails()
httpHandler.CallsMade.Should().ContainSingle(s => s == "http://image-processor/convert");
result.Should().BeFalse();
context.Asset.Should().NotBeNull();
context.Asset.Error.Should().Be("Appetiser Error: error");
}

[Theory]
Expand Down
31 changes: 25 additions & 6 deletions src/protagonist/Engine/Ingest/Image/Appetiser/AppetiserClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ public async Task<bool> ProcessImage(IngestionContext context)
var flags = new ImageProcessorFlags(context, GetJP2FilePath(context.AssetId, false));
logger.LogDebug("Got flags '{Flags}' for {AssetId}", flags, context.AssetId);
var responseModel = await CallImageProcessor(context, flags);
await ProcessResponse(context, responseModel, flags);
return true;

if (responseModel is AppetiserResponseModel successResponse)
{
await ProcessResponse(context, successResponse, flags);
return true;
}
else if (responseModel is AppetiserResponseErrorModel failResponse)
{
context.Asset.Error = $"Appetiser Error: {failResponse.Message}";
return false;
}

return false;
}
catch (Exception e)
{
Expand Down Expand Up @@ -87,7 +98,7 @@ public async Task<bool> ProcessImage(IngestionContext context)
return (dest, thumb);
}

private async Task<AppetiserResponseModel> CallImageProcessor(IngestionContext context,
private async Task<IAppetiserResponse> CallImageProcessor(IngestionContext context,
ImageProcessorFlags processorFlags)
{
// call tizer/appetiser
Expand All @@ -102,10 +113,18 @@ private async Task<AppetiserResponseModel> CallImageProcessor(IngestionContext c
}

using var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();

IAppetiserResponse? responseModel;

if (response.IsSuccessStatusCode)
{
responseModel = await response.Content.ReadFromJsonAsync<AppetiserResponseModel>();
}
else
{
responseModel = await response.Content.ReadFromJsonAsync<AppetiserResponseErrorModel>();
}

// TODO - it's possible to get a 200 when appetiser doesn't do anything, e.g. body not understood
var responseModel = await response.Content.ReadFromJsonAsync<AppetiserResponseModel>();
return responseModel;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Engine.Ingest.Image.Appetiser;

public interface IAppetiserResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Engine.Ingest.Image.Appetiser;

/// <summary>
/// Response model for receiving error requests back from Appetiser.
/// </summary>
public class AppetiserResponseErrorModel : IAppetiserResponse
{
public string Message { get; set; }
public string Status { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Engine.Ingest.Image.Appetiser;
/// <summary>
/// Response model for receiving requests back from Appetiser.
/// </summary>
public class AppetiserResponseModel
public class AppetiserResponseModel : IAppetiserResponse
{
public string ImageId { get; set; }
public string JobId { get; set; }
Expand Down

0 comments on commit 6c9b4b2

Please sign in to comment.