Added better handling of failed POST request.