From 05aaf07e05c1e1ddf670178e721879b31ff8be10 Mon Sep 17 00:00:00 2001 From: iglocska Date: Mon, 11 Nov 2019 15:33:15 +0100 Subject: [PATCH] fix: [internal] tag attacher could run into a situation where an invalid tag's creation failure is not caught - returns puzzling error messages --- app/Controller/TagsController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Controller/TagsController.php b/app/Controller/TagsController.php index c5c1e9778..120f749ed 100644 --- a/app/Controller/TagsController.php +++ b/app/Controller/TagsController.php @@ -944,7 +944,10 @@ class TagsController extends AppController throw new MethodNotAllowedException('Tag not found and insufficient privileges to create it.'); } $this->Tag->create(); - $this->Tag->save(array('Tag' => array('name' => $tag, 'colour' => $this->Tag->random_color()))); + $result = $this->Tag->save(array('Tag' => array('name' => $tag, 'colour' => $this->Tag->random_color()))); + if (!$result) { + return $this->RestResponse->saveFailResponse('Tags', 'attachTagToObject', false, __('Unable to create tag. Reason: ' . json_encode($this->Tag->validationErrors)), $this->response->type()); + } $existingTag = $this->Tag->find('first', array('recursive' => -1, 'conditions' => array('Tag.id' => $this->Tag->id))); } else { throw new NotFoundException('Invalid Tag.');