Selaa lähdekoodia

fix bug of pois

maguohua1 6 vuotta sitten
vanhempi
sitoutus
347c1ea817
2 muutettua tiedostoa jossa 11 lisäystä ja 16 poistoa
  1. 9 14
      controller/v1/cities.js
  2. 2 2
      prototype/addressComponent.js

+ 9 - 14
controller/v1/cities.js

@@ -92,22 +92,17 @@ class CityHandle extends AddressComponent{
 		}
 	}
 	async pois(req, res, next){
-		const geohash = req.params.geohash;
 		try{
+			const geohash = req.params.geohash || '';
 			if (geohash.indexOf(',') == -1) {
-				throw new Error('参数错误')
+				res.send({
+					status: 0,
+					type: 'ERROR_PARAMS',
+					message: '参数错误',
+				})
+				return;
 			}
-		}catch(err){
-			console.log('参数错误');
-			res.send({
-				status: 0,
-				type: 'ERROR_PARAMS',
-				message: '参数错误',
-			})
-			return 
-		}
-		const poisArr = geohash.split(',');
-		try{
+			const poisArr = geohash.split(',');
 			const result = await this.getpois(poisArr[0], poisArr[1]);
 			const address = {
 				address: result.result.address,
@@ -119,7 +114,7 @@ class CityHandle extends AddressComponent{
 			}
 			res.send(address);
 		}catch(err){
-			console.log('getpois返回信息失败');
+			console.log('getpois返回信息失败', err);
 			res.send({
 				status: 0,
 				type: 'ERROR_DATA',

+ 2 - 2
prototype/addressComponent.js

@@ -179,7 +179,7 @@ class AddressComponent extends BaseComponent {
 				throw new Error('获取具体位置信息失败');
 			}
 		}catch(err){
-			console.log('geocoder获取定位失败')
+			console.log('geocoder获取定位失败', err);
 			throw new Error(err);
 		}
 	}
@@ -208,7 +208,7 @@ class AddressComponent extends BaseComponent {
 				throw new Error('通过获geohash取具体位置失败');
 			}
 		}catch(err){
-			console.log('getpois获取定位失败')
+			console.log('getpois获取定位失败', err)
 			throw new Error(err);
 		}
 	}