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'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:
asyncTask<Result<Response,Error>>InvokeAsync(){varfirstResponse=awaitGetResponseAsStringAsync(...);// network call that returns raw API response, may failvarparsedFirstResponse=serializer.Deserialize<FirstResponse>(firstResponse);// may fail because API has weird contractsvarsecondResponse=awaithttpClient.GetStringAsync/* some parts of parsedFirstResponse */);// may failvarparsedSecondResponse=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.
The text was updated successfully, but these errors were encountered:
This looks similar to the state monad (or maybe not, it's been awhile since I read that article). I would introduce a custom class to handle the intermediate result of the parsing and only use Result<T, E> at the edges of the parsing function. There's just too much going on during parsing and trying to cram all that into the "standard" Result won't do any good.
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:
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.The text was updated successfully, but these errors were encountered: