API exceptions.

This commit is contained in:
Alexey Skobkin 2015-10-01 21:05:11 +03:00
parent de234f1290
commit f351fc22ff
3 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1,9 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Service\Exceptions;
class ApiException extends \Exception
{
}

View File

@ -0,0 +1,9 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Service\Exceptions;
class SubscriptionManagerException extends \Exception
{
}

View File

@ -7,6 +7,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Guzzle\Service\Client;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException;
/**
* Basic Point.im user API functions from /api/user/*
@ -136,6 +137,12 @@ class UserApi extends AbstractApi
$user = new User();
$user->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;
}