Skip to content

Commit

Permalink
fix(grpc): return back Result factory
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Jan 18, 2023
1 parent 76289a5 commit 25eee62
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Sitko.Core.Grpc/GrpcCallResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Sitko.Core.Grpc;
using Sitko.Core.App.Results;

namespace Sitko.Core.Grpc;

public class GrpcCallResult
{
Expand All @@ -25,5 +27,17 @@ public GrpcCallResult(Exception exception, string? error = null) : this(error ??
public string[] Error => errors.ToArray();
public Exception? Exception { get; }

public static GrpcCallResult Result(IOperationResult operationResult)
{
if (operationResult.IsSuccess)
{
return Ok();
}

return operationResult.Exception is not null
? new GrpcCallResult(operationResult.Exception, operationResult.ErrorMessage)
: new GrpcCallResult(operationResult.ErrorMessage ?? "Error");
}

public static GrpcCallResult Ok() => new();
}

0 comments on commit 25eee62

Please sign in to comment.