handle http redirects and errors