Added some basic error handling to API call code.