How could I propagate an mapped error #159
Unanswered
mr-gilberto
asked this question in
Q&A
Replies: 1 comment
-
|
you can map the error before returning from the repository using override suspend fun getUser(): ApiResponse<User> =
userService.getUser()
.mapFailure { failure ->
MappedError(failure.message())
}or if you want full control: return when (val result = userService.getUser()) {
is ApiResponse.Success -> result
is ApiResponse.Failure.Error -> ApiResponse.Failure.Error(MappedError(result.message()))
is ApiResponse.Failure.Exception -> result
}that way the viewmodel just sees the already-mapped type and does not need to know about the raw error shape. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to map the error in the repository instead of the viewModel, so I would like to add a mapper for it . and just access to the new Object mapped directly on the viewModel.
is it a good approach ? ,
Beta Was this translation helpful? Give feedback.
All reactions