Check error first so we don't assume we have resp

In certain error situations it would blow up because resp.statusCode can not be accessed because resp is undefined. Check err first before proceeding.