|
28 | 28 | public class OpenWeatherApi { |
29 | 29 |
|
30 | 30 | private static final int NO_LIMIT = -1; |
| 31 | + private static final int SUCCESS_CODE = 200; |
31 | 32 |
|
32 | 33 | @SuppressWarnings("NullableProblems") |
33 | 34 | @NonNull |
@@ -122,7 +123,9 @@ public void onError(Throwable e) { |
122 | 123 |
|
123 | 124 | @Override |
124 | 125 | public void onNext(CurrentWeather currentWeather) { |
125 | | - listener.onResponse(currentWeather); |
| 126 | + if (currentWeather.getStatusCode() == SUCCESS_CODE) |
| 127 | + listener.onResponse(currentWeather); |
| 128 | + else listener.onError(currentWeather.statusMessage()); |
126 | 129 | } |
127 | 130 | }); |
128 | 131 |
|
@@ -160,7 +163,9 @@ public void onError(Throwable e) { |
160 | 163 |
|
161 | 164 | @Override |
162 | 165 | public void onNext(CurrentWeather currentWeather) { |
163 | | - listener.onResponse(currentWeather); |
| 166 | + if (currentWeather.getStatusCode() == SUCCESS_CODE) |
| 167 | + listener.onResponse(currentWeather); |
| 168 | + else listener.onError(currentWeather.statusMessage()); |
164 | 169 | } |
165 | 170 | }); |
166 | 171 |
|
@@ -196,7 +201,9 @@ public void onError(Throwable e) { |
196 | 201 |
|
197 | 202 | @Override |
198 | 203 | public void onNext(CurrentWeather currentWeather) { |
199 | | - listener.onResponse(currentWeather); |
| 204 | + if (currentWeather.getStatusCode() == SUCCESS_CODE) |
| 205 | + listener.onResponse(currentWeather); |
| 206 | + else listener.onError(currentWeather.statusMessage()); |
200 | 207 | } |
201 | 208 | }); |
202 | 209 |
|
@@ -236,7 +243,9 @@ public void onError(Throwable e) { |
236 | 243 |
|
237 | 244 | @Override |
238 | 245 | public void onNext(CurrentWeather currentWeather) { |
239 | | - listener.onResponse(currentWeather); |
| 246 | + if (currentWeather.getStatusCode() == SUCCESS_CODE) |
| 247 | + listener.onResponse(currentWeather); |
| 248 | + else listener.onError(currentWeather.statusMessage()); |
240 | 249 | } |
241 | 250 | }); |
242 | 251 | } |
@@ -272,7 +281,9 @@ public void onError(Throwable e) { |
272 | 281 |
|
273 | 282 | @Override |
274 | 283 | public void onNext(MultipleCitiesWeathers citiesWeathers) { |
275 | | - listener.onResponse(citiesWeathers); |
| 284 | + if (citiesWeathers.getStatusCode() == SUCCESS_CODE) |
| 285 | + listener.onResponse(citiesWeathers); |
| 286 | + else listener.onError(citiesWeathers.statusMessage()); |
276 | 287 | } |
277 | 288 | }); |
278 | 289 | } |
@@ -327,7 +338,9 @@ public void onError(Throwable e) { |
327 | 338 |
|
328 | 339 | @Override |
329 | 340 | public void onNext(WeatherForecast weatherForecasts) { |
330 | | - listener.onResponse(weatherForecasts); |
| 341 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 342 | + listener.onResponse(weatherForecasts); |
| 343 | + else listener.onError(weatherForecasts.statusMessage()); |
331 | 344 | } |
332 | 345 | }); |
333 | 346 | } |
@@ -413,7 +426,9 @@ public void onError(Throwable e) { |
413 | 426 |
|
414 | 427 | @Override |
415 | 428 | public void onNext(WeatherForecast weatherForecasts) { |
416 | | - listener.onResponse(weatherForecasts); |
| 429 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 430 | + listener.onResponse(weatherForecasts); |
| 431 | + else listener.onError(weatherForecasts.statusMessage()); |
417 | 432 | } |
418 | 433 | }); |
419 | 434 | } |
@@ -470,7 +485,9 @@ public void onError(Throwable e) { |
470 | 485 |
|
471 | 486 | @Override |
472 | 487 | public void onNext(WeatherForecast weatherForecasts) { |
473 | | - listener.onResponse(weatherForecasts); |
| 488 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 489 | + listener.onResponse(weatherForecasts); |
| 490 | + else listener.onError(weatherForecasts.statusMessage()); |
474 | 491 | } |
475 | 492 | }); |
476 | 493 | } |
@@ -524,7 +541,9 @@ public void onError(Throwable e) { |
524 | 541 |
|
525 | 542 | @Override |
526 | 543 | public void onNext(WeatherForecast weatherForecasts) { |
527 | | - listener.onResponse(weatherForecasts); |
| 544 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 545 | + listener.onResponse(weatherForecasts); |
| 546 | + else listener.onError(weatherForecasts.statusMessage()); |
528 | 547 | } |
529 | 548 | }); |
530 | 549 | } |
@@ -607,7 +626,9 @@ public void onError(Throwable e) { |
607 | 626 |
|
608 | 627 | @Override |
609 | 628 | public void onNext(WeatherForecast weatherForecasts) { |
610 | | - listener.onResponse(weatherForecasts); |
| 629 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 630 | + listener.onResponse(weatherForecasts); |
| 631 | + else listener.onError(weatherForecasts.statusMessage()); |
611 | 632 | } |
612 | 633 | }); |
613 | 634 | } |
@@ -664,7 +685,9 @@ public void onError(Throwable e) { |
664 | 685 |
|
665 | 686 | @Override |
666 | 687 | public void onNext(WeatherForecast weatherForecasts) { |
667 | | - listener.onResponse(weatherForecasts); |
| 688 | + if (weatherForecasts.getStatusCode() == SUCCESS_CODE) |
| 689 | + listener.onResponse(weatherForecasts); |
| 690 | + else listener.onError(weatherForecasts.statusMessage()); |
668 | 691 | } |
669 | 692 | }); |
670 | 693 | } |
|
0 commit comments