Cleaned up error handling code. New behaviour for failed requests.