Added better error handling and printing of http response