• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 178
1
  • Mark post as helpful
  • send pies
  • 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: 178
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try to change it to the following :
 
But, Still don't work
 
Maha Sakka
Ranch Hand
Posts: 178
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution, I use CoroutineExceptionHandler :
 
Rancher
Posts: 476
7
Android Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


Well done!
 
    Bookmark Topic Watch Topic
  • New Topic