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

Show recipe error instead if throwing an exeption #16148

Merged
merged 21 commits into from
May 25, 2024
Merged
Changes from 1 commit
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
@@ -1,3 +1,4 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand All @@ -6,26 +7,44 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using OrchardCore.Deployment.Remote.Services;
using OrchardCore.Deployment.Remote.ViewModels;
using OrchardCore.Deployment.Services;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Recipes.Models;

namespace OrchardCore.Deployment.Remote.Controllers
{
public class ImportRemoteInstanceController : Controller
{
private readonly RemoteClientService _remoteClientService;
private readonly IDeploymentManager _deploymentManager;
private readonly INotifier _notifier;
private readonly ILogger _logger;
private readonly IDataProtector _dataProtector;

protected readonly IHtmlLocalizer H;
protected readonly IStringLocalizer S;

public ImportRemoteInstanceController(
IDataProtectionProvider dataProtectionProvider,
RemoteClientService remoteClientService,
IDeploymentManager deploymentManager)
IDeploymentManager deploymentManager,
INotifier notifier,
IHtmlLocalizer<ImportRemoteInstanceController> htmlLocalizer,
IStringLocalizer<ImportRemoteInstanceController> stringLocalizer,
ILogger<ImportRemoteInstanceController> logger)
{
_deploymentManager = deploymentManager;
_notifier = notifier;
_logger = logger;
_remoteClientService = remoteClientService;
H = htmlLocalizer;
S = stringLocalizer;
_dataProtector = dataProtectionProvider.CreateProtector("OrchardCore.Deployment").ToTimeLimitedDataProtector();
}

Expand Down Expand Up @@ -70,6 +89,18 @@ public async Task<IActionResult> Import(ImportViewModel model)

await _deploymentManager.ImportDeploymentPackageAsync(new PhysicalFileProvider(tempArchiveFolder));
}
catch (RecipeExecutionException e)
{
_logger.LogError(e, "Unable to import a recipe from JSON input.");

await _notifier.ErrorAsync(H["The import failed with the following errors: {0}", string.Join(' ', e.StepResult.Errors.SelectMany(x => x.Value))]);
}
catch (Exception e)
{
_logger.LogError(e, "Unable to import a package.");

ModelState.AddModelError(string.Empty, S["Unexpected error occurred while importing the recipe."]);
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
}
finally
{
if (System.IO.File.Exists(tempArchiveName))
Expand Down
Loading