Check for null response

I have found that the `res` object is not always set. This PR guards against that.