Add error check in case proxying disallowed by server.
Refactor slightly for better flow.