Error handling in Android : easy way!

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2024

ความคิดเห็น • 13

  • @subyk6046
    @subyk6046 ปีที่แล้ว +2

    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)
    }

  • @rmbr
    @rmbr 2 ปีที่แล้ว +3

    I liked the video because the content was good and liking it was free. 😂

    • @Renaro
      @Renaro  2 ปีที่แล้ว +1

      Paga nada então senta o dedo no like! Valew!

  • @theandroidexecption5137
    @theandroidexecption5137 2 ปีที่แล้ว +2

    Nice video you have one repo i think what the arquitecture what you are using is realy good and i like to learn

    • @Renaro
      @Renaro  2 ปีที่แล้ว +2

      Here you can see it th-cam.com/video/j2TnQqtNr5U/w-d-xo.html

    • @Renaro
      @Renaro  2 ปีที่แล้ว +1

      It is clean architecture+ MVVM

  • @cyriltheandroid
    @cyriltheandroid 2 ปีที่แล้ว +1

    Nice video!

  • @nymexe
    @nymexe ปีที่แล้ว +1

    What about the kotlin.Result class?

    • @Renaro
      @Renaro  ปีที่แล้ว

      Indeed you should be careful to import the correct class, better name it something other than Result

    • @nymexe
      @nymexe ปีที่แล้ว +2

      @@Renaro I mean, what is wrong with kotlin.Result class? You are creating your own, I think it's just more code to maintain.

    • @Renaro
      @Renaro  ปีที่แล้ว +1

      @@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.

    • @nymexe
      @nymexe ปีที่แล้ว +1

      @@Renaro Got it. Thank you!

    • @ggwp57229
      @ggwp57229 ปีที่แล้ว

      ​@@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.