Darshan Hiranandani : How do I handle errors and exceptions returned by an API?

198
1
02-25-2024 10:23 PM
DarshanHiranandani
New Contributor II

Hii, I am Darshan Hiranandani, I am looking to improve my approach to handling errors and exceptions when working with APIs. Could anyone share their insights or best practices for effectively managing and responding to errors returned by APIs? Whether it is dealing with status codes, parsing error messages, or implementing retry logic, I'd love to hear your experiences and recommendations. Thank you in advance for your valuable input!

 
 
 
 
Tags (1)
0 Kudos
1 Reply
AlexanderDanielPratama
Esri Contributor

You could create a common library for the API you specified. I am using Python, so probably I will work utilize the urllib3 module. python - urllib3 how to find code and message of Http error - Stack Overflow

if you want to implemen retry logic you could use while == True, if its pass the error break the it with False. If  certain try still error you could use sys.exit()

Hope it helps you

Cheers 

0 Kudos