--- /dev/null
+<?php
+namespace Civi\API\Exception;
+
+require_once 'api/Exception.php';
+class NotImplementedException extends \API_Exception {
+ public function __construct($message, $extraParams = array(), Exception $previous = NULL) {
+ parent::__construct($message, \API_Exception::NOT_IMPLEMENTED, $extraParams, $previous);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+namespace Civi\API\Exception;
+
+require_once 'api/Exception.php';
+class UnauthorizedException extends \API_Exception {
+ public function __construct($message, $extraParams = array(), Exception $previous = NULL) {
+ parent::__construct($message, \API_Exception::UNAUTHORIZED, $extraParams, $previous);
+ }
+}
\ No newline at end of file
$resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest));
$apiRequest = $resolveEvent->getApiRequest();
if (!$resolveEvent->getApiProvider()) {
- throw new \API_Exception("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)", \API_Exception::NOT_IMPLEMENTED);
+ throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
}
return array($resolveEvent->getApiProvider(), $apiRequest);
}
public function authorize($apiProvider, $apiRequest) {
$event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest));
if (!$event->isAuthorized()) {
- throw new \API_Exception("Authorization failed", \API_Exception::UNAUTHORIZED);
+ throw new \Civi\API\Exception\UnauthorizedException("Authorization failed");
}
}
$permissions = implode(' and ', $permissions);
}
// FIXME: Generating the exception ourselves allows for detailed error but doesn't play well with multiple authz subscribers.
- throw new \API_Exception("API permission check failed for {$apiRequest['entity']}/{$apiRequest['action']} call; insufficient permission: require $permissions", \API_Exception::UNAUTHORIZED);
+ throw new \Civi\API\Exception\UnauthorizedException("API permission check failed for {$apiRequest['entity']}/{$apiRequest['action']} call; insufficient permission: require $permissions");
}
$event->authorize();