Skip to content

Commit

Permalink
Add UserException class and catch subscription exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Caiger committed May 24, 2017
1 parent f96ae98 commit 3ed9b25
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Exception/UserException.php
@@ -0,0 +1,11 @@
<?php

/*
* Exception that will be passed to the OIDC client.
*/

namespace xrow\restBundle\Exception;

class UserException extends \Exception
{
}
20 changes: 15 additions & 5 deletions Helper/ApiFunctions.php
Expand Up @@ -22,6 +22,7 @@
use eZ\Publish\Core\MVC\Symfony\Security\UserWrapped as eZUserWrapped;
use xrow\restBundle\Security\OAuth2Token;
use xrow\restBundle\Exception\OAuth2AuthenticateException;
use xrow\restBundle\Exception\UserException;
use xrow\restBundle\HttpFoundation\xrowJsonResponse as JsonResponse;

class ApiFunctions
Expand Down Expand Up @@ -124,12 +125,21 @@ public function setAuthentication(Request $request, $bundle = 'FOS')
if ($user instanceof eZUserWrapped) {
$user = $user->getWrappedUser();
}

// Set subscriptions to session for permissions for legacy login
$userData = array('user' => $this->crmPlugin->getUser($user),
'subscriptions' => $this->crmPlugin->getSubscriptions($user));
$session->set('CRMUserData', $userData);
$return = array('session_name' => $session->getName(),
'session_id' => $session->getId());
try {
$userData = array(
'user' => $this->crmPlugin->getUser($user),
'subscriptions' => $this->crmPlugin->getSubscriptions($user)
);
$session->set('CRMUserData', $userData);
$return = array(
'session_name' => $session->getName(),
'session_id' => $session->getId()
);
} catch(UserException $e) {
return $this->jsonExceptionResponse($e);
}
return new JsonResponse(array(
'result' => $return,
'type' => 'CONTENT',
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -118,3 +118,6 @@ This is a bundle which creates an API for third party application. The data for
This bundle is under the MIT license.
See the complete [license](Resources/meta/LICENSE) in the bundle.

## Development

See the [notes for developers](Resources/doc/develop.md)
15 changes: 15 additions & 0 deletions Resources/doc/develop.md
@@ -0,0 +1,15 @@
# Notes for developers

## Exceptions

If you want an error message to be returned to the API client, throw the `UserException` exception.

use xrow\restBundle\Exception\UserException;

...

throw(new UserException('My error has occurred'));

The error message and stack trace will also be logged.

Take care not to expose secure information to the client!

0 comments on commit 3ed9b25

Please sign in to comment.