Skip to content

Commit

Permalink
correct 400/404 status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothauer committed Feb 5, 2024
1 parent 18cdcd3 commit a318efe
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Controller/WorkshopsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand 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) {

Expand Down

0 comments on commit a318efe

Please sign in to comment.