Skip to content
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
11 changes: 7 additions & 4 deletions Apps.Contentful/Actions/EntryActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,13 @@ public async Task<DownloadContentOutput> SetEntryLocalizableFieldsFromHtmlFile(
Transformation? transformation = null;
if (Xliff2Serializer.IsXliff2(content) || Xliff1Serializer.IsXliff1(content))
{
transformation = Transformation.Parse(content, input.Content.Name);
content = transformation.Target().Serialize();
if (content == null)
throw new PluginMisconfigurationException("XLIFF did not contain any files");
content = ErrorHandler.ExecuteWithErrorHandling(() =>
{
transformation = Transformation.Parse(content, input.Content.Name);
return
transformation.Target().Serialize() ??
throw new PluginMisconfigurationException("XLIFF did not contain any files");
});
}

errors.AddRange(_customSizeValidationService.Validate(content, input.Locale, input.SkipCustomValidationStep == true));
Expand Down
2 changes: 1 addition & 1 deletion Apps.Contentful/Apps.Contentful.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<Product>Contentful</Product>
<Description>The headless content management system</Description>
<Version>1.8.14</Version>
<Version>1.8.15</Version>
<AssemblyName>Apps.Contentful</AssemblyName>
</PropertyGroup>

Expand Down
7 changes: 7 additions & 0 deletions Apps.Contentful/Constants/KnownErrorMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Apps.Contentful.Constants;

public static class KnownErrorMessages
{
public const string CannotConvertToContent = "Cannot convert to content, no original data found";
public const string CouldNotDetectContentType = "Could not detect any valid content type this library can process";
}
29 changes: 29 additions & 0 deletions Apps.Contentful/Utils/ErrorHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Apps.Contentful.Constants;
using Blackbird.Applications.Sdk.Common.Exceptions;

namespace Apps.Contentful.Utils;

public static class ErrorHandler
{
private static readonly Dictionary<string, string> ErrorMappings = new()
{
{ KnownErrorMessages.CouldNotDetectContentType, "This file type is not supported" },
{ KnownErrorMessages.CannotConvertToContent, "Cannot generate the original document format. The uploaded XLIFF is missing the original file's structural data." }
};

public static T ExecuteWithErrorHandling<T>(Func<T> action)
{
try
{
return action();
}
catch (Exception ex)
{
var mapping = ErrorMappings.FirstOrDefault(m => ex.Message.Contains(m.Key));
if (mapping.Key != null)
throw new PluginMisconfigurationException(mapping.Value);

throw new PluginApplicationException(ex.Message);
}
}
}
12 changes: 0 additions & 12 deletions Tests.Contentful/Tests.Contentful.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json.example">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down