Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving error reporting from appetiser #704

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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)
JackLewis-digirati marked this conversation as resolved.
Show resolved Hide resolved
{
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
Loading