Showing
1 changed file
with
9 additions
and
2 deletions
@@ -14,10 +14,11 @@ exports.search = function (req, res) { | @@ -14,10 +14,11 @@ exports.search = function (req, res) { | ||
14 | params.push(key + "=" + encodeURI(req.body[key])); | 14 | params.push(key + "=" + encodeURI(req.body[key])); |
15 | } | 15 | } |
16 | var url = searchDomain + "/search.json?viewNum=" + size + "&" + params.join('&'); | 16 | var url = searchDomain + "/search.json?viewNum=" + size + "&" + params.join('&'); |
17 | - console.log(url); | ||
18 | - request({url: url}, function (error, response, body) { | 17 | + request({url: url}, function (error, httpResponse, body) { |
19 | var data = {}; | 18 | var data = {}; |
20 | data.list = []; | 19 | data.list = []; |
20 | + if (!error && httpResponse.statusCode == 200) { | ||
21 | + try{ | ||
21 | body = JSON.parse(body); | 22 | body = JSON.parse(body); |
22 | var dataList = body.data.product_list; | 23 | var dataList = body.data.product_list; |
23 | var goodslist = []; | 24 | var goodslist = []; |
@@ -40,6 +41,12 @@ exports.search = function (req, res) { | @@ -40,6 +41,12 @@ exports.search = function (req, res) { | ||
40 | data.nums = data.list.length;//记录每一页数据量 | 41 | data.nums = data.list.length;//记录每一页数据量 |
41 | //console.log("最终data", data); | 42 | //console.log("最终data", data); |
42 | res.json({data: {data: data, code: 200}}); | 43 | res.json({data: {data: data, code: 200}}); |
44 | + }catch(ex){ | ||
45 | + res.json({data: {data: data, code: 500}}); | ||
46 | + } | ||
47 | + }else{ | ||
48 | + res.json({data: {data: data, code: 500}}); | ||
49 | + } | ||
43 | }); | 50 | }); |
44 | }; | 51 | }; |
45 | 52 |
-
Please register or login to post a comment