From 8eb086f1a8b7ebbef40fcee9eb038d12d2236525 Mon Sep 17 00:00:00 2001 From: Eero af Heurlin Date: Tue, 3 Jun 2008 16:22:22 +0300 Subject: [PATCH] include request info on transport exception, sanity check tag parser results --- plugins/ajatus/couchdb/exceptions.php | 7 +++++++ plugins/ajatus/couchdb/transport.php | 16 +++++++++++++++- plugins/ajatus/helpers/tag.php | 6 ++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/plugins/ajatus/couchdb/exceptions.php b/plugins/ajatus/couchdb/exceptions.php index 9475f35..4a4355b 100644 --- a/plugins/ajatus/couchdb/exceptions.php +++ b/plugins/ajatus/couchdb/exceptions.php @@ -79,6 +79,13 @@ class couchdb_replicator_exception extends couchdb_exception */ class couchdb_transport_exception extends couchdb_exception { + var $request = null; + + public function __construct($message, $code=0, &$request) + { + $this->request =& $request; + parent::__construct($message, $code); + } } ?> \ No newline at end of file diff --git a/plugins/ajatus/couchdb/transport.php b/plugins/ajatus/couchdb/transport.php index 98d0733..959203a 100644 --- a/plugins/ajatus/couchdb/transport.php +++ b/plugins/ajatus/couchdb/transport.php @@ -178,7 +178,21 @@ class couchdb_transport if (! in_array($this->lastStatusCode, range(200, 299))) { - throw new couchdb_transport_exception("Don't know how to handle response with code {$this->lastStatusCode}."); + $error_json = $this->clean_json($req->getResponseBody()); + /* Try to parse the couchdb error but it seems to be weirdly formed and json_decode cannot handle it + if (isset($error_json->reason)) + { + echo "DEBUG: \$error_json->reason
\n";
+                var_dump($error_json->reason);
+                echo "
\n"; + //$error_reason_json = json_decode(str_replace('\\n', "\n", $error_json->reason)); + $error_reason_json = json_decode(str_replace('\\n', "\n", $error_json->reason)); + echo "DEBUG: \$error_reason_json
\n";
+                var_dump($error_reason_json);
+                echo "
\n"; + } + */ + throw new couchdb_transport_exception("Don't know how to handle response with code {$this->lastStatusCode}.", $this->lastStatusCode, $req); } $this->lastRevision = $req->getResponseHeader('x-couch-revid'); diff --git a/plugins/ajatus/helpers/tag.php b/plugins/ajatus/helpers/tag.php index b038e2a..0bb4b59 100644 --- a/plugins/ajatus/helpers/tag.php +++ b/plugins/ajatus/helpers/tag.php @@ -50,13 +50,15 @@ class ajatus_helpers_tag $value = ''; $cparts = explode(':', $tag); - if (is_array($cparts)) + if ( is_array($cparts) + && count($cparts) === 2) { $context = $cparts[0]; $tag = $cparts[1]; } $vparts = explode('=', $tag); - if (is_array($vparts)) + if (is_array($vparts) + && count($vparts) === 2) { $value = $vparts[1]; $tag = $vparts[0]; -- 2.11.4.GIT