Simplify failure handling

This commit is contained in:
2025-11-01 19:28:20 +09:00
parent 821eeb41ae
commit 737e581f75
5 changed files with 19 additions and 21 deletions

View File

@ -2,6 +2,6 @@
{ {
public interface IResultGetter public interface IResultGetter
{ {
Task<ResultGetterResponse> GetAsync(); Task<bool> GetAsync();
} }
} }

View File

@ -6,12 +6,12 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon
{ {
public class ExportNsiItemGetter_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ResultGetterBase(client, scope, operation) public class ExportNsiItemGetter_15_7_0_1(IClient client, IServiceScope scope, Operation operation) : ResultGetterBase(client, scope, operation)
{ {
public override async Task<ResultGetterResponse> GetAsync() public override async Task<bool> GetAsync()
{ {
var result = await client.NsiCommon.GetExportNsiItemResultAsync(operation.MessageGuid!); var result = await client.NsiCommon.GetExportNsiItemResultAsync(operation.MessageGuid!);
if (!result.Ready) if (!result.Ready)
{ {
return ResultGetterResponse.NotReady; return false;
} }
if (result.Success) if (result.Success)
@ -20,10 +20,10 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters.NsiCommon
var registry = await registryService.GetRegistryByOperationIdAsync(operation.Id); var registry = await registryService.GetRegistryByOperationIdAsync(operation.Id);
// TODO // TODO
return ResultGetterResponse.Successful; return true;
} }
return ResultGetterResponse.Failed; throw Failure(result.ErrorMessage);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using Hcs.Broker; using Hcs.Broker;
using Hcs.Broker.Api.Request.Adapter;
using Hcs.WebApp.Data.Hcs; using Hcs.WebApp.Data.Hcs;
namespace Hcs.WebApp.BackgroundServices.ResultGetters namespace Hcs.WebApp.BackgroundServices.ResultGetters
@ -9,6 +10,15 @@ namespace Hcs.WebApp.BackgroundServices.ResultGetters
protected readonly IServiceScope scope = scope; protected readonly IServiceScope scope = scope;
protected readonly Operation operation = operation; protected readonly Operation operation = operation;
public abstract Task<ResultGetterResponse> GetAsync(); public abstract Task<bool> GetAsync();
protected Exception Failure(IErrorMessage? errorMessage)
{
if (errorMessage != null)
{
return new Exception($"{errorMessage.ErrorCode} - {errorMessage.Description}");
}
return new Exception("Критическая ошибка");
}
} }
} }

View File

@ -1,9 +0,0 @@
namespace Hcs.WebApp.BackgroundServices.ResultGetters
{
public enum ResultGetterResponse
{
NotReady,
Successful,
Failed
}
}

View File

@ -69,13 +69,10 @@ namespace Hcs.WebApp.BackgroundServices
try try
{ {
var resultGetter = resultGetterFactory.CreateResultGetter(scope, client, entry.operation); var resultGetter = resultGetterFactory.CreateResultGetter(scope, client, entry.operation);
var response = await resultGetter.GetAsync(); var success = await resultGetter.GetAsync();
switch (response) if (success)
{ {
case ResultGetterResponse.Successful: entry.state.done = true;
case ResultGetterResponse.Failed:
entry.state.done = true;
break;
} }
} }
catch (Exception e) catch (Exception e)