From 5b7483ada52f261d060c7f4afc2f3b267b5011da Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Mon, 22 Feb 2021 16:28:29 +0100 Subject: [PATCH] return 404 for details when no bject is found in database Fixes #2157. --- lib-php/website/details.php | 13 +++++++++---- test/bdd/api/details/simple.feature | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib-php/website/details.php b/lib-php/website/details.php index 130dcaf8..bd7df12c 100644 --- a/lib-php/website/details.php +++ b/lib-php/website/details.php @@ -81,10 +81,15 @@ if ($sOsmType && $iOsmId > 0) { exit; } } -} - -if ($sPlaceId === false) userError('Please select a place id'); + if ($sPlaceId === false) { + throw new Exception('No place with that OSM ID found.', 404); + } +} else { + if ($sPlaceId === false) { + userError('Required parameters missing. Need either osmtype/osmid or place_id.'); + } +} $iPlaceID = (int)$sPlaceId; @@ -140,7 +145,7 @@ $sSQL .= " WHERE place_id = $iPlaceID"; $aPointDetails = $oDB->getRow($sSQL, null, 'Could not get details of place object.'); if (!$aPointDetails) { - userError('Unknown place id.'); + throw new Exception('No place with that place ID found.', 404); } $aPointDetails['localname'] = $aPointDetails['localname']?$aPointDetails['localname']:$aPointDetails['housenumber']; diff --git a/test/bdd/api/details/simple.feature b/test/bdd/api/details/simple.feature index a9b6d6a7..c38018bc 100644 --- a/test/bdd/api/details/simple.feature +++ b/test/bdd/api/details/simple.feature @@ -44,7 +44,7 @@ Feature: Object details Scenario Outline: Details via unknown OSM id When sending details query for - Then a HTTP 400 is returned + Then a HTTP 404 is returned Examples: | object | -- 2.39.5