fix: [internal] tag attacher could run into a situation where an invalid tag's creation failure is not caught

- returns puzzling error messages
pull/5404/head
iglocska 2019-11-11 15:33:15 +01:00
parent 11ee95aeb3
commit 05aaf07e05
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 4 additions and 1 deletions

View File

@ -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.');