Permalink
Browse files

Start returning some meaningful data when something goes wrong.

  • Loading branch information...
1 parent 9335dda commit 06809fbbd8f04caad57f127dae885cc171fd95f4 Marco Sampellegrini committed Oct 29, 2011
Showing with 39 additions and 3 deletions.
  1. +8 −2 events/event.update_gist.php
  2. +31 −1 lib/class.xpathr.php
@@ -65,7 +65,13 @@ protected function __trigger()
$params = Symphony::Engine()->Page()->_param;
$id = $params['gist-id'];
- $id = Xpathr::updateGist($id, $options);
- if ($id) redirect(URL. '/view/'. $id. '?update');
+ try {
+ $id = Xpathr::updateGist($id, $options);
+ if ($id) redirect(URL. '/view/'. $id. '?update');
+ }
+ catch (XpathrException $ex)
+ {
+ return $ex->asNode(self::ROOTELEMENT, $options);
+ }
}
}
View
@@ -249,4 +249,34 @@ protected static function api($url, $options = array())
- class XpathrException extends Exception { }
+ class XpathrException extends Exception {
+ public function asNode($node = 'xpathr', $data = array())
+ {
+ $xml = new XMLElement($node);
+ $xml->appendChild(
+ new XMLElement('message', $this->getMessage())
+ );
+
+ if (!$data) return $xml;
+
+ $data = General::array_map_recursive('htmlentities', $data);
+
+ $post = new XMLElement('data');
+ self::buildDataNode($post, $data);
+ $xml->appendChild($post);
+
+ return $xml;
+ }
+
+ protected static function buildDataNode(XMLElement $node, $data = array())
+ {
+ foreach ($data as $k => $v)
+ {
+ $item = new XMLElement('item', null, array('key' => $k));
+ if (is_array($v)) self::buildDataNode($item, $v);
+ else $item->setValue($v);
+
+ $node->appendChild($item);
+ }
+ }
+ }

0 comments on commit 06809fb

Please sign in to comment.