diff --git a/CHANGELOG.md b/CHANGELOG.md index a9311522c..b03248897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ [#1687](https://github.com/nextcloud/cookbook/pull/1687) @christianlupus - Prevent popup from falsely showing during loading of the app [#1764](https://github.com/nextcloud/cookbook/pull/1764) @christianlupus +- Fix unclear error message if recipe is already existing + [#1770](https://github.com/nextcloud/cookbook/pull/1770) @SethFalco ### Maintenance - Fix URL of Transifex after upstream subdomain change diff --git a/lib/Controller/Implementation/RecipeImplementation.php b/lib/Controller/Implementation/RecipeImplementation.php index 7000c96d2..b7a7b8774 100644 --- a/lib/Controller/Implementation/RecipeImplementation.php +++ b/lib/Controller/Implementation/RecipeImplementation.php @@ -109,6 +109,13 @@ public function update($id) { $recipeData = $this->restParser->getParameters(); try { $file = $this->service->addRecipe($recipeData); + } catch (RecipeExistsException $ex) { + $json = [ + 'msg' => $ex->getMessage(), + 'file' => $ex->getFile(), + 'line' => $ex->getLine(), + ]; + return new JSONResponse($json, Http::STATUS_CONFLICT); } catch (NoRecipeNameGivenException $ex) { $json = [ 'msg' => $ex->getMessage(), diff --git a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php index a8d73d92f..9114ad95b 100644 --- a/tests/Unit/Controller/Implementation/RecipeImplementationTest.php +++ b/tests/Unit/Controller/Implementation/RecipeImplementationTest.php @@ -416,6 +416,24 @@ public function testUpdateNoName(): void { $this->assertEquals($errorMsg, $ret->getData()['msg']); } + public function testUpdateConflictingName(): void { + $this->ensureCacheCheckTriggered(); + + $recipe = ['a', 'recipe', 'as', 'array']; + + $errorMsg = "Another recipe with that name already exists"; + $ex = new RecipeExistsException($errorMsg); + + $this->restParser->method('getParameters')->willReturn($recipe); + $this->recipeService->expects($this->once())->method('addRecipe')->with($recipe)->willThrowException($ex); + $this->dbCacheService->expects($this->never())->method('addRecipe'); + + $ret = $this->sut->update(1); + + $this->assertEquals(409, $ret->getStatus()); + $this->assertEquals($errorMsg, $ret->getData()['msg']); + } + public function testCreate(): void { $this->ensureCacheCheckTriggered();