Common code for handling httpResponse