From f351fc22ffb0b2dd23ed7b74693f86e06729d876 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Thu, 1 Oct 2015 21:05:11 +0300 Subject: [PATCH] API exceptions. --- .../Service/Exceptions/ApiException.php | 9 +++++++++ .../Exceptions/SubscriptionManagerException.php | 9 +++++++++ .../Bundle/PointToolsBundle/Service/UserApi.php | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Service/Exceptions/ApiException.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Service/Exceptions/SubscriptionManagerException.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Exceptions/ApiException.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Exceptions/ApiException.php new file mode 100644 index 0000000..0eb8fd5 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Exceptions/ApiException.php @@ -0,0 +1,9 @@ +setId((int) $userData['id']); $this->em->persist($user); + + try { + $this->em->flush(); + } catch (\Exception $e) { + throw new ApiException(sprintf('Error while flushing new user [%d] %s', $user->getId(), $user->getLogin()), 0, $e); + } } // Updating data @@ -146,12 +153,16 @@ class UserApi extends AbstractApi $user->setName($userData['name']); } + try { + $this->em->flush(); + } catch (\Exception $e) { + throw new ApiException(sprintf('Error while flushing changes for [%d] %s', $user->getId(), $user->getLogin()), 0, $e); + } + $resultUsers[] = $user; } } - $this->em->flush(); - return $resultUsers; }