Catch bad return codes on API calls and wait for a good one.