adds logic around redirects and client/server errors