Authored by htoooth

加固错误处理

... ... @@ -67,13 +67,13 @@ const showMain = (req, res, next) => {
pid: pid,
channel: channel,
gender: gender
}, nullUserInfo)).then(result=> {
}, nullUserInfo)).then((result)=> {
return res.render('product/detail', Object.assign({
module: 'product',
page: 'detail',
title_more: true,
title: result.seo.title + ' | ' + SEO_SLOGAN,
keywords: result.seo.keywords.replace(/~+/, ''),
title: _.get(result, 'seo.title', '') + ' | ' + SEO_SLOGAN,
keywords: _.get(result, 'seo.keywords', '').replace(/~+/, ''),
description_more: true,
description: result.description
}, result));
... ...
... ... @@ -1012,7 +1012,7 @@ const _getSeoByGoodsInfo = (goodsInfo, navs) => {
goodsInfo = goodsInfo || {};
navs = navs || [];
if (!_.isEmpty(goodsInfo.brandName)) {
if (goodsInfo.brandName) {
title = goodsInfo.brandName + ' ';
brandName = goodsInfo.brandName;
}
... ... @@ -1041,7 +1041,7 @@ const _getSeoByGoodsInfo = (goodsInfo, navs) => {
*/
const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
return co(function*() {
if (_.isEmpty(origin)) {
if (_.isEmpty(origin) || _.isEmpty(origin.data)) {
return {};
}
... ... @@ -1289,8 +1289,8 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
return {
goodsInfo: result,
banner: _.isEmpty(bandInfo) ? null : bandInfo,
statGoodsInfo: statGoodsInfo,
latestWalk: 5 // 只显示5个
statGoodsInfo: statGoodsInfo
};
})();
};
... ... @@ -1304,7 +1304,7 @@ const getDetailHeader = (pid, uid, isStudent, vipLevel, dataMd5, cookie) => {
return productAPI.getProductAsync(pid, uid, isStudent, vipLevel)
.then(currentUserProductInfo)
.then((result) => {
if (_.isEmpty(result) || !_.get(result, 'goodsInfo.md5', '')) {
if (_.isEmpty(result) || !_.get(result, 'goodsInfo.md5')) {
return {
code: 204, // 没有改变数据
data: {}
... ... @@ -1337,37 +1337,45 @@ const saleReturn = (skn) => {
*/
const showMainAsync = (data) => {
return co(function * () {
let curUserProduct = _.partial(_detailDataPkg, _, data.uid, data.vipLevel, data.gid, data.saveInCookies);
// 获取商品基本信息
let productData = yield productAPI.getProductAsync(data.pid, data.uid, data.isStudent, data.vipLevel);
// 获取并处理商品基本信息
let productInfo = yield productAPI.getProductAsync(data.pid, data.uid, data.isStudent, data.vipLevel)
.then(curUserProduct);
if (_.isEmpty(productInfo) || _.isEmpty(productInfo.goodsInfo)) {
if (_.isEmpty(productData.data)) {
return Promise.reject({
code: 404
code: 404,
message: 'app.product.data api wrong'
});
}
let smallSortId = _.get(productData, 'data.smallSortId');
let maxSortId = _.get(productData, 'data.maxSortId');
let productId = _.get(productData, 'data.product_id');
let productSkn = _.get(productData, 'data.product_skn');
let curUserProduct = _.partial(_detailDataPkg, _, data.uid, data.vipLevel, data.gid, data.saveInCookies);
let requestData = yield Promise.all([
_getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender), // 导航
HeaderModel.requestHeaderData(data.channel), // 头部数据
_getProductIntroAsync(productInfo.goodsInfo.productId, productInfo.goodsInfo.skn) // 商品详细介绍
_getSortNavAsync(smallSortId, data.gender), // 面包屑导航
HeaderModel.requestHeaderData(data.channel), // 通用头部数据
_getProductIntroAsync(productId, productSkn), // 商品详细介绍
curUserProduct(productData) // 商品详细价格
]);
let smallSortNavigator = requestData[0];
let navigatorHeader = requestData[1];
let productDescription = requestData[2];
let productInfo = requestData[3];
// 拼装数据
let result = {};
// 商品数据详情
// 商品价格
result.productDetailPage = true;
result.detail = productInfo;
// 咨询和评论
result.detail.consultComment = true;
// 商品介绍
let intro = _getIntroInfo(productSkn, maxSortId, productDescription);
result.deatil = Object.assign(result.detail, intro);
// seo
result.seo = _getSeoByGoodsInfo(productInfo.goodsInfo, smallSortNavigator);
... ... @@ -1381,16 +1389,17 @@ const showMainAsync = (data) => {
result.detail.pathNav = _.concat(
homeService.getHomeChannelNav(data.channel),
smallSortNavigator,
[{name: productInfo.goodsInfo.name}]
[{name: _.get(productInfo, 'goodsInfo.name')}]
);
// 头部数据
result.headerData = navigatorHeader.headerData;
// 商品详细介绍
let intro = _getIntroInfo(productInfo.goodsInfo.skn, productInfo.goodsInfo.maxSortId, productDescription);
// 咨询和评论
result.detail.consultComment = true;
result.deatil = Object.assign(result.detail, intro);
// 最近浏览,最多5条记录
result.detail.latestWalk = 5;
return result;
})();
... ...