Added some error handling for API exceptions