Skip to content

Commit

Permalink
Add generic PHP exception matching for javax.jcr.*
Browse files Browse the repository at this point in the history
  • Loading branch information
rndstr committed Dec 1, 2010
1 parent 871e522 commit 21cbbdf
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Jackalope/Transport/Davex/Request.php
Expand Up @@ -208,17 +208,31 @@ public function execute()
$errClass = $err->getElementsByTagNameNS(Client::NS_DCR, 'class')->item(0)->textContent;
$errMsg = $err->getElementsByTagNameNS(Client::NS_DCR, 'message')->item(0)->textContent;

$exceptionMsg = 'HTTP ' . $httpCode . ': ' . $errMsg;
switch($errClass) {
case 'javax.jcr.NoSuchWorkspaceException':
throw new \PHPCR\NoSuchWorkspaceException('HTTP '.$httpCode . ": $errMsg");
throw new \PHPCR\NoSuchWorkspaceException($exceptionMsg);
case 'javax.jcr.nodetype.NoSuchNodeTypeException':
throw new \PHPCR\NodeType\NoSuchNodeTypeException('HTTP '.$httpCode . ": $errMsg");
throw new \PHPCR\NodeType\NoSuchNodeTypeException($exceptionMsg);
case 'javax.jcr.ItemNotFoundException':
throw new \PHPCR\ItemNotFoundException('HTTP '.$httpCode . ": $errMsg");
throw new \PHPCR\ItemNotFoundException($exceptionMsg);
case 'javax.jcr.nodetype.ConstraintViolationException':
throw new \PHPCR\NodeType\ConstraintViolationException($exceptionMsg);

//TODO: map more errors here?
default:
throw new \PHPCR\RepositoryException('HTTP '.$httpCode . ": $errMsg ($errClass)");

// try generic
$class = substr($errClass, strlen('javax.jcr.'));
$class = explode('.', $class);
array_walk($class, function(&$ns) { $ns = ucfirst(str_replace('nodetype', 'NodeType', $ns)); });
$class = '\\PHPCR\\'.implode('\\', $class);

if (class_exists($class)) {
throw new $class($exceptionMsg);
} else {
throw new \PHPCR\RepositoryException($exceptionMsg . " ($errClass)");
}
}
}
}
Expand Down Expand Up @@ -274,4 +288,4 @@ public function executeJson()
//TODO: are there error responses in json format? if so, handle them
return $json;
}
}
}

0 comments on commit 21cbbdf

Please sign in to comment.