Refactor requests error handling.