encapsulate api calls in rescue loop