Result
Result copied to clipboard
Add Correlation Id to Error Statuses
Should we have more options for including correlation ids? And if so, rather than having separate methods for all of them, would it make sense to bake it into a single parameter object, like:
public record ErrorList(IEnumerable<string> ErrorMessages, string? CorrelationId);
?
Then the factory methods would just take in (ErrorList errorList) and we wouldn't need any overloads or alternate methods.
Originally posted by @ardalis in https://github.com/ardalis/Result/issues/169#issuecomment-1989829677
I can see there is a CorrelationId in Result
public static implicit operator Result<T>(Result result) => new Result<T>(default(T))
{
Status = result.Status,
Errors = result.Errors,
SuccessMessage = result.SuccessMessage,
CorrelationId = result.CorrelationId,
ValidationErrors = result.ValidationErrors,
};
However I can't figure out how to set CorrelationId using static methods such as Error, Invalid, NotFound etc... for example ..
return Result<DetailedDeathRecordDto>.Error(message);
Is the purpose of this issue to set CorrelationId when returning a Result<T> using these this static methods?
If not how do you set the CorrelationId?
Currently in my Minimal Api I am logging the CorrelationId successfully using serilog like so
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithCorrelationIdHeader("x-correlation-id")
);
My expectation or hope was that "x-correlation-id" value would have been added by default to Result<T> CorrelationId property.
At a minimum I would like to be able to set the CorrelationId.
What am I doing wrong?
@AminurRouf The current plan is to create a factory method for Error that takes in a record ErrorList which has properties for IEnumerable