liuxiulin преди 2 месеца
родител
ревизия
86e1683c8d
променени са 1 файла, в които са добавени 3 реда и са изтрити 0 реда
  1. 3 0
      api.go

+ 3 - 0
api.go

@@ -122,6 +122,9 @@ func GetWeatherInfo(location, key string) (*WeatherInfoResp, error) {
 	if err != nil {
 		return nil, err
 	}
+	if len(info.Results) == 0 {
+		return nil, errors.New(fmt.Sprintf("天气查询失败:%s", location))
+	}
 	result.Location = info.Results[0].Location.Name
 	result.Text = info.Results[0].Now.Text
 	result.Code = info.Results[0].Now.Code