From a318efe9cc54440f27739ab03c38f37d2dc515f7 Mon Sep 17 00:00:00 2001 From: mrothauer Date: Mon, 5 Feb 2024 22:08:41 +0100 Subject: [PATCH] correct 400/404 status codes --- src/Controller/WorkshopsController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Controller/WorkshopsController.php b/src/Controller/WorkshopsController.php index 74b5728d1..34cf16dea 100644 --- a/src/Controller/WorkshopsController.php +++ b/src/Controller/WorkshopsController.php @@ -405,7 +405,7 @@ public function getWorkshopsWithCityFilter() { $city = $this->request->getQuery('city'); if ($city === null || strlen($city) < 3) { - throw new NotFoundException('city not passed or invalid (min 3 chars)'); + return $this->response->withStatus(400)->withType('json')->withStringBody(json_encode('city not passed or invalid (min 3 chars)')); } $workshops = $this->Workshop->find('all', @@ -422,6 +422,10 @@ public function getWorkshopsWithCityFilter() { ], order: ['Workshops.name' => 'asc']); + if ($workshops->count() == 0) { + return $this->response->withStatus(404)->withType('json')->withStringBody(json_encode('no workshops found')); + } + $preparedWorkshops = []; foreach($workshops as $workshop) {