res could be nil, please check before accessing res.code or res.body