Added error handling for post request function