Skip to content

Commit a677205

Browse files
authored
Merge pull request #52551 from nextcloud/checkResultArray
fix(WeatherStatus): Check if result is an array
2 parents df69eb5 + 9c8e026 commit a677205

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

apps/weather_status/lib/Service/WeatherStatusService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,19 @@ private function searchForAddress(string $address): array {
257257
];
258258
$url = 'https://nominatim.openstreetmap.org/search';
259259
$results = $this->requestJSON($url, $params);
260-
if ($results['error'] !== null) {
261-
return $results;
260+
261+
if (isset($results['error'])) {
262+
return ['error' => (string)$results['error']];
262263
}
263-
if (count($results) > 0) {
264-
return $results[0];
264+
265+
if (count($results) > 0 && is_array($results[0])) {
266+
return [
267+
'display_name' => (string)($results[0]['display_name'] ?? null),
268+
'lat' => (string)($results[0]['lat'] ?? null),
269+
'lon' => (string)($results[0]['lon'] ?? null),
270+
];
265271
}
272+
266273
return ['error' => $this->l10n->t('No result.')];
267274
}
268275

0 commit comments

Comments
 (0)