Error handling code for http stuff