Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

How to use coroutine scope to call web service and handle error kotlin

 
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I develop an android app with Kotlin, api 28. I also use swaggerHub and swagger.json to get all WS. In swaggerHub, I export the client sdk Kotlin.After export the "Kotlin_client_generated" file with swagger, and add it in my project.
Here is an example of ws code, among others ws :

After a while of research, about How to consume this WS, I found that I should use coroutine and I use a GlobalScope with Dispatchers :

I want to handle the exception with try/catch and dispaly the error in a Toast,How can I do that.
I found that I should use Coroutine Scope instead of Global Scope and the Global Scope is highly disouraged.
So,How to use coroutine scope to call web service and handle error ?
Could you please help me to solve my problem
 
Maha Sakka
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to change it to the following :
 
But, Still don't work
 
Maha Sakka
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the solution, I use CoroutineExceptionHandler :
 
Rancher
Posts: 589
9
Android Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maha Sakka wrote:I found the solution, I use CoroutineExceptionHandler :


Well done!
 
reply
    Bookmark Topic Watch Topic
  • New Topic