fixed error handling when doing HTTP requests