Refactor response error handling