If you use it for api call, make sure, that you will handle errors from api, because errors from api are in the end successful api call... I recommend try/catch block and use if/else in try (simple example how i mean it): try { if(client.status.code in 200-299) { return AsyncResult.Success(data) } else { AsyncResult.Error(Exception("${client.status.code} -> $data")) //error msg from api is usual string } } catch (e: Exception) { AsyncResult.Error(e) }
@@nymexe Indeed a good option as well for the network layer, there you will always have either a success with data or an exception, but for domain errors you might want to define more different types of errors, think for example about a backend response with an invalid input field and validations, then you might need some other types of errors that Result from Kotlin does not support.
@@Renaro But your class also have 2 (error, success) types like a kotlin.Result approach. You can wrap any Throwable to Failure. So I think don't need to create bicycles.
If you use it for api call, make sure, that you will handle errors from api, because errors from api are in the end successful api call... I recommend try/catch block and use if/else in try (simple example how i mean it):
try {
if(client.status.code in 200-299) {
return AsyncResult.Success(data)
} else {
AsyncResult.Error(Exception("${client.status.code} -> $data")) //error msg from api is usual string
}
} catch (e: Exception) {
AsyncResult.Error(e)
}
I liked the video because the content was good and liking it was free. 😂
Paga nada então senta o dedo no like! Valew!
Nice video you have one repo i think what the arquitecture what you are using is realy good and i like to learn
Here you can see it th-cam.com/video/j2TnQqtNr5U/w-d-xo.html
It is clean architecture+ MVVM
Nice video!
What about the kotlin.Result class?
Indeed you should be careful to import the correct class, better name it something other than Result
@@Renaro I mean, what is wrong with kotlin.Result class? You are creating your own, I think it's just more code to maintain.
@@nymexe Indeed a good option as well for the network layer, there you will always have either a success with data or an exception, but for domain errors you might want to define more different types of errors, think for example about a backend response with an invalid input field and validations, then you might need some other types of errors that Result from Kotlin does not support.
@@Renaro Got it. Thank you!
@@Renaro But your class also have 2 (error, success) types like a kotlin.Result approach. You can wrap any Throwable to Failure. So I think don't need to create bicycles.