I have three folders (presentation, domain, data) and I am building an android app, the problem I want to provide is a special exception in the domain layer . however, these messages are in a different language, to support diff languages in android we should use string resources.
class NoNetworkException(error: Throwable) : MyError(getString(R.string.no_network_available_error), error)
here is my question, the error messages come from my domain, however the domain layer becomes not pure kotlin , any idea
CodePudding user response:
I think you should always put abstractions in your domain layer. So, I think something like this would actually help you to keep your code in a clean-architecture way.
Domain
abstract class Error: Exception() {
abstract val errorMessage: String
}
Data
class NoInternetError(override val errorMessage: String) : Error()
I would imagine you are doing networking calls in your data layer so, you can get a hold of the context
in the data layer easily or if you are using dependency injection you can inject this error in the places you want to throw it.
NoInternetError(context.getString(R.string.no_network_available_error))
CodePudding user response:
I have three folders (presentation, domain, data) and I am building an android app
I guess that you explored the clean-architecture, regards this, you can read this article: