diff --git a/src/Controller/Api/EntryRestController.php b/src/Controller/Api/EntryRestController.php index b043449a5..001afe00b 100644 --- a/src/Controller/Api/EntryRestController.php +++ b/src/Controller/Api/EntryRestController.php @@ -798,9 +798,12 @@ class EntryRestController extends WallabagRestController $errors = $validator->validate($entry); if (\count($errors) > 0) { - $errorsString = (string) $errors; + $errorsString = ''; + foreach ($errors as $error) { + $errorsString .= $error->getMessage() . "\n"; + } - return $this->sendResponse($errorsString); + throw new BadRequestHttpException($errorsString); } $this->entityManager->persist($entry); diff --git a/tests/Controller/Api/EntryRestControllerTest.php b/tests/Controller/Api/EntryRestControllerTest.php index df9a6927f..e148d0c08 100644 --- a/tests/Controller/Api/EntryRestControllerTest.php +++ b/tests/Controller/Api/EntryRestControllerTest.php @@ -614,10 +614,10 @@ class EntryRestControllerTest extends WallabagApiTestCase 'public' => 1, ]); - $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(400, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertStringContainsString('The url \'"wallabagIsAwesome"\' is not a valid url', $content); + $this->assertStringContainsString('The url \'"wallabagIsAwesome"\' is not a valid url', $content['message']); } public function testPostEntry()