Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 165
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: 165
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: 165
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution, I use CoroutineExceptionHandler :
 
Rancher
Posts: 437
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!
 
Hey! You're stepping on my hand! Help me tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!