Skip to content

Commit

Permalink
Added Response and Status from Neo4j Responses to Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
prehfeldt committed Nov 25, 2011
1 parent fe6c9f1 commit 7303377
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 28 deletions.
10 changes: 4 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@
</target>

<target name="docblox" depends="prepare">
<exec dir="${base}" executable="docblox">
<arg line="project:parse -d ${source}/src/Vkg -t ${basedir}/builds/docblox"/>
</exec>
<exec dir="${base}" executable="docblox">
<arg line="project:transform -s ${base}/builds/docblox/structure.xml -t ${base}/builds/docs"/>
</exec>

<exec dir="${base}" executable="docblox">
<arg line="run -d ${source} -t ${base}/builds/docblox" />
</exec>
</target>

<target name="release_single" depends="phpunit">
Expand Down
6 changes: 5 additions & 1 deletion lib/Neo4j/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @author pr
* @package neo4j-rest-api
*/
class HttpException extends \Exception { }
class HttpException extends \Exception {
public function __construct($message, $code) {
parent::__construct($message, $code);
}
}

?>
4 changes: 3 additions & 1 deletion lib/Neo4j/Exceptions/HttpNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use Neo4j\Exceptions\HttpException;

class HttpNotFoundException extends HttpException {

public function __construct($message) {
parent::__construct($message, 404);
}
}

?>
2 changes: 1 addition & 1 deletion lib/Neo4j/FullPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function inflateFromResponse ($neo_db, $response) {
$response = HTTPUtility::get($current['self']);

if (200 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getStatus(), $response->getStatus());
}

$relations[] = Relationship::inflateFromResponse($neo_db, $response->getResponse());
Expand Down
28 changes: 27 additions & 1 deletion lib/Neo4j/GraphDatabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getNodeById($node_id) {
} else if (404 == $response->getStatus()) {
throw new HttpNotFoundException($response->getResponseAsJson());
} else {
throw new HttpException($response->getStatus());
throw new HttpException($response->getStatus(), $response->getStatus());
}
}

Expand Down Expand Up @@ -90,6 +90,32 @@ public function getQueryManager($engine = 'cypher') {
throw new \RuntimeException('Unknown query engine ' . $engine);
}
}

/**
*
* @param array $operation
* @return boolean
* @throws HttpException
*/
public function runBatchOperation(array $operation) {
$uri = $this->getBaseUri() . 'batch';
$response = HTTPUtility::post($uri, $operation);

if (200 == $response->getStatus()) {
$parsedResponse = array();
foreach ($response->getResponse() as $current) {
if (true == array_key_exists('body', $current)) {
$parsedResponse[] = Node::inflateFromResponse($this, $current['body']);
} else {
$parsedResponse[] = $current;
}
}

return $parsedResponse;
} else {
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
}
}

?>
2 changes: 1 addition & 1 deletion lib/Neo4j/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getIndexConfig ($type) {
$response = HTTPUtility::get($indexUri);

if (200 != $response->getStatus() AND 204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$indices = $response->getResponse();
Expand Down
6 changes: 3 additions & 3 deletions lib/Neo4j/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function create ($name, $type, $config = array()) {
$response = HTTPUtility::post($indexUri, $indexConfig);

if (201 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

return $this->spawnNewIndex($name, $type);
Expand All @@ -98,7 +98,7 @@ public function delete ($name, $type) {
$response = HTTPUtility::delete($indexUri);

if (204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

return true;
Expand Down Expand Up @@ -146,7 +146,7 @@ public function getIndexList ($type) {
$response = HTTPUtility::get($indexUri);

if (200 != $response->getStatus() AND 204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$indices = array();
Expand Down
8 changes: 4 additions & 4 deletions lib/Neo4j/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function delete($deleteRelations = true) {

$response = HTTPUtility::delete($this->getUri());
if (204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$this->id = null;
Expand All @@ -79,13 +79,13 @@ public function save() {


if (201 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
} else {
$response = HTTPUtility::put($this->getUri() . '/properties', $this->getProperties());

if (204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
}

Expand Down Expand Up @@ -205,7 +205,7 @@ public function runTraverser (Traverser $traverser, $returnType) {
$response = HTTPUtility::post($url, $traverser->getSettings());

if (200 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$temp = array();
Expand Down
6 changes: 3 additions & 3 deletions lib/Neo4j/NodeIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function add ($node) {
$response = HTTPUtility::post($this->getIndexUri(), $data);

if (201 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public function delete ($node) {
$response = HTTPUtility::delete($indexUri);

if (204 != $response->getStatus() AND 404 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
}
}
Expand All @@ -103,7 +103,7 @@ public function getByQuery ($query) {
$response = HTTPUtility::get($indexUri);

if (200 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

if (0 >= count($response->getResponse())) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Neo4j/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct ($neoDb, $start, $end, $length, $nodes, $relations)
* @return various
*/
public function __get ($name) {
if ('neoDb' == $name) throw new Exception('Forbidden!');
if ('neoDb' == $name) throw new \Exception('Forbidden!');
return $this->$name;
}

Expand All @@ -97,7 +97,7 @@ public static function inflateFromResponse ($neo_db, $response) {
$response = HTTPUtility::get($current);

if (200 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$relations[] = Relationship::inflateFromResponse($neo_db, $response->getResponse());
Expand Down
6 changes: 3 additions & 3 deletions lib/Neo4j/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public function save() {
$response = HTTPUtility::post($this->getUri(), $payload);

if (201 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
} else {
$response = HTTPUtility::put($this->getUri() . '/properties', $this->getProperties());

if (204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}
}

Expand All @@ -191,7 +191,7 @@ public function delete() {
$response = HTTPUtility::delete($this->getUri());

if (204 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

$this->id = null;
Expand Down
4 changes: 2 additions & 2 deletions lib/Neo4j/RelationshipIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function delete ($relation) {
$response = HTTPUtility::delete($indexUri);

if (204 != $response->getStatus() AND 404 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getStatus(), $response->getStatus());
}
}
}
Expand All @@ -104,7 +104,7 @@ public function getByQuery ($query) {
$response = HTTPUtility::get($indexUri);

if (200 != $response->getStatus()) {
throw new HttpException($response->getStatus());
throw new HttpException($response->getResponseAsJson(), $response->getStatus());
}

if (0 >= count($response->getResponse())) {
Expand Down

0 comments on commit 7303377

Please sign in to comment.