res can be nil, so please check it before accessing res.code