From 168f18859636080f0d35a81c1a43c040addf8e40 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 22 Feb 2018 14:16:49 +0100 Subject: [PATCH] Show hint in OCS API for user creation * adds a 107 error code together with the hint of the exception * logs the exception as warning * fixes #7946 Signed-off-by: Morris Jobke --- .../lib/Controller/UsersController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index ffae68d5a9..22ee0402e4 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -31,6 +31,7 @@ namespace OCA\Provisioning_API\Controller; use OC\Accounts\AccountManager; +use OC\HintException; use OC\Settings\Mailer\NewUserMailHelper; use OC_Helper; use OCP\App\IAppManager; @@ -187,15 +188,22 @@ class UsersController extends OCSController { try { $newUser = $this->userManager->createUser($userid, $password); - $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); + $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']); if (is_array($groups)) { foreach ($groups as $group) { $this->groupManager->get($group)->addUser($newUser); - $this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']); + $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']); } } return new DataResponse(); + } catch (HintException $e ) { + $this->logger->logException($e, [ + 'message' => 'Failed addUser attempt with hint exception.', + 'level' => \OCP\Util::WARN, + 'app' => 'ocs_api', + ]); + throw new OCSException($e->getHint(), 107); } catch (\Exception $e) { $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); throw new OCSException('Bad request', 101);