Example #1
0
 private function generateErrorForException(\Exception $exception)
 {
     if ($exception instanceof CommandInvalidException) {
         $formError = $exception->getForm()->getErrors(true)->current();
         $path = $formError->getOrigin()->getPropertyPath();
         if ($path !== null) {
             // We got PropertyPathInterface or maybe even a string (undocumented).
             $path = (string) $path;
         }
         return new E\Api\BadRequest($formError->getMessage(), $path);
     } elseif ($exception instanceof ConstraintViolationException) {
         return $exception->getError();
     } elseif ($exception instanceof UsernameNotFoundException) {
         return new E\Security\BadCredentials();
     } elseif ($exception instanceof AccessDeniedException) {
         $token = $this->tokenStorage->getToken();
         if ($token && $this->tokenStorage->getToken()->getRoles()) {
             return new E\Security\NotAuthorized();
         } else {
             return new E\Security\NotAuthenticated();
         }
     } elseif ($exception instanceof ProtocolException) {
         return $this->getErrorForOxygenProtocolException($exception);
     } else {
         return new E\Api\UnexpectedError();
     }
 }
 /**
  * Returns the unwrapped exception object in case we are dealing with
  * a PHP 7 Error object
  *
  * @param \Exception $exception The object to unwrap
  * @return \Exception|\Error
  */
 protected function _unwrap($exception)
 {
     return $exception instanceof PHP7ErrorException ? $exception->getError() : $exception;
 }