This should be rewritten as

    if (!error && response && response.getResponseHeader)

(no need for `typeof` here - just check whether that property exists)