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
When calling downstream API's there are times when the consuming program needs the details of an error so that domain specific actions can be taken.
Example:
MyBlazorApp calls MyBlazorAppApi to add a user to a downstream service using a DownstreamApi wrapper, which makes the actual REST calls to the downstream service.
publicasyncTask<Result<DownstreamUser>>AddDownstreamUser(stringemail){// make httpClient calls here...// return success with downstreamUser// or deserialize errors to errorData and return Result.Error<ErrorData>(errorData);}
For example, DownstreamApi reports that the user already exists and returns a 400 bad request with a specific error code in the errorData that's returned. Other 400 errors are show stoppers, but this one is not. If I know the actual error code that the downstream api is sending me, I can discriminate and take the proper action.
Using Result.Error<T> (or possibly Result.Invalid<T>) allows me to return the errorData up to the AddMyBlazorUser endpoint where a second call can be made to find the existing user via their email address and return the MyBlazorUser instance to the MyBlazorApp original caller.
As it stands, I am using some special delimiters to embed their error message in the standard collection of strings and then looking for it in the caller. Working but it could be improved.
The text was updated successfully, but these errors were encountered:
When calling downstream API's there are times when the consuming program needs the details of an error so that domain specific actions can be taken.
Example:
MyBlazorApp
callsMyBlazorAppApi
to add a user to a downstream service using aDownstreamApi
wrapper, which makes the actual REST calls to the downstream service.MyBlazorAppApi endpoint:
DownstreamAPI wrapper function:
For example,
DownstreamApi
reports that the user already exists and returns a 400 bad request with a specific error code in the errorData that's returned. Other 400 errors are show stoppers, but this one is not. If I know the actual error code that the downstream api is sending me, I can discriminate and take the proper action.Using
Result.Error<T>
(or possiblyResult.Invalid<T>
) allows me to return the errorData up to the AddMyBlazorUser endpoint where a second call can be made to find the existing user via their email address and return the MyBlazorUser instance to the MyBlazorApp original caller.As it stands, I am using some special delimiters to embed their error message in the standard collection of strings and then looking for it in the caller. Working but it could be improved.
The text was updated successfully, but these errors were encountered: