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 struggling to see how I can convert from one error type to another.
I have a function that returns a TaskEither<ApiError, Client>. I want to use the resulting client in another function that returns a TaskEither<ServiceError, String> . The two error types are not sharing a common base class.
I tried to chain the calls but could not make it work. The code is something along these lines. Also tried to add a mapLeft but did not work either. I have been going in circles and any help would be greatly appreciated.
The library is awesome, but would love to see more examples for common use-cases.
TaskEither<ServiceError, String> apiCall(URI uri) {
returngetClient()
.mapLeft((error) =>ServiceError.mapError(error))
.flatMap((client) =>TaskEither.tryCatch(
() async=> client.get(uri),
ServiceError.mapError
).chainEither( // …. Remaining code to parse response
}
// the signature for getClient is as followTaskEither<ApiError, String> getClient() {
…
}
The text was updated successfully, but these errors were encountered:
The second ServiceError.mapError inside tryCatch cannot have the same signature, since the error in tryCatch gives you Object + StackTrace instead of ApiError.
If for example you refactor like below it compiles:
I’m struggling to see how I can convert from one error type to another.
I have a function that returns a TaskEither<ApiError, Client>. I want to use the resulting client in another function that returns a TaskEither<ServiceError, String> . The two error types are not sharing a common base class.
I tried to chain the calls but could not make it work. The code is something along these lines. Also tried to add a mapLeft but did not work either. I have been going in circles and any help would be greatly appreciated.
The library is awesome, but would love to see more examples for common use-cases.
The text was updated successfully, but these errors were encountered: