-
Notifications
You must be signed in to change notification settings - Fork 315
Description
I'm writing an important integration with a buggy third-party API that constantly changes its returning models. For debugging purposes and to be able to reprocess or replay its responses, I want to store plain responses along with some metadata like request duration. So, I'm looking for something like:
async Task<Result<Response, Error>> InvokeAsync()
{
var firstResponse = await GetResponseAsStringAsync(...); // network call that returns raw API response, may fail
var parsedFirstResponse = serializer.Deserialize<FirstResponse>(firstResponse); // may fail because API has weird contracts
var secondResponse = await httpClient.GetStringAsync/* some parts of parsedFirstResponse */); // may fail
var parsedSecondResponse = serializer.Deserialize<SecondResponse>(secondResponse); // may fail
}And I want the Result I return to have some shared context in both success and error cases. In the case of success, it will have information about two successful responses, including their raw values and durations. In the case of failure, it will contain all available information (i.e., if processing fails during parsing, I want the Result to contain the raw response that caused parsing issues).
Has anyone ever faced such requirements before? I'm considering adding Result<T, TError, TContext> to my project.