You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I may call in a method different services. When result is success I use result.Value to continue but if there are errors like conflict or anything else I want to return and stop execution there but I want to keep errors. Map is not always possible (I guess). Is there a good way to accomplish this? Should I use map with an empty value like return result.Map(new RandomClass()) only to keep errors since value wont matter at this point. Or can I just return result.Map();?
public Result<int> ReturnIntResult(int id)
{
Result<Foo> resultFromService = _service.GetFoo(id)
if(!result.IsSucces)
{
//How can I return a type Result<int> with errors from resultFromService? Like conflict or anything else. I have seen some basic example with int and string using Map. But sometime _service can return value and errors which value is used later but mapping is not necessary needed for the value. Only for the error;
return ???;
}
return new Result<int>(resultFromService.Value);
}
The text was updated successfully, but these errors were encountered:
@ma-lar please try to use the Error function i think it may can solve your issue also you can use :
even it may be better if errors functions is not related to any types
publicResult<int>ReturnIntResult(intid){Result<Foo>resultFromService=_service.GetFoo(id);if(!resultFromService.IsSuccess){// Use Error method with ErrorList to return a Result<int> with errors from resultFromServicevarerrorList=newErrorList(resultFromService.Errors,resultFromService.CorrelationId);returnResult<int>.Error(errorList);}returnResult<int>.Success(resultFromService.Value.Id);}
Question:
I may call in a method different services. When result is success I use result.Value to continue but if there are errors like conflict or anything else I want to return and stop execution there but I want to keep errors. Map is not always possible (I guess). Is there a good way to accomplish this? Should I use map with an empty value like return result.Map(new RandomClass()) only to keep errors since value wont matter at this point. Or can I just return result.Map();?
The text was updated successfully, but these errors were encountered: