[4637] trunk/htdocs/system/plugins/pingback/pingback.plugin.php: Catch RemoteRequest exceptions and generate XMLRPCExceptions from them, rather than letting the error bubble up.

0 views
Skip to first unread message

svn-N...@habariproject.org

unread,
Nov 27, 2010, 7:12:30 PM11/27/10
to habar...@googlegroups.com
Revision
4637
Author
chrismeller
Date
2010-11-28 00:12:29 +0000 (Sun, 28 Nov 2010)

Log Message

Catch RemoteRequest exceptions and generate XMLRPCExceptions from them, rather than letting the error bubble up.

Modified Paths

Diff

Modified: trunk/htdocs/system/plugins/pingback/pingback.plugin.php (4636 => 4637)


--- trunk/htdocs/system/plugins/pingback/pingback.plugin.php	2010-11-28 00:11:44 UTC (rev 4636)
+++ trunk/htdocs/system/plugins/pingback/pingback.plugin.php	2010-11-28 00:12:29 UTC (rev 4637)
@@ -127,12 +127,21 @@
 			}
 
 			// Retrieve source contents
-			$rr = new RemoteRequest( $source_uri );
-			$rr->execute();
-			if ( ! $rr->executed() ) {
-				throw new XMLRPCException( 16 );
+			try {
+				$rr = new RemoteRequest( $source_uri );
+				$rr->execute();
+				if ( ! $rr->executed() ) {
+					throw new XMLRPCException( 16 );
+				}
+				$source_contents = $rr->get_response_body();
 			}
-			$source_contents = $rr->get_response_body();
+			catch ( XMLRPCException $e ) {
+				// catch our special type of exception and re-throw it
+				throw $e;
+			}
+			catch ( Exception $e ) {
+				throw new XMLRPCException( -32300 );
+			}
 
 			// encoding is converted into internal encoding.
 			// @todo check BOM at beginning of file before checking for a charset attribute
@@ -219,11 +228,16 @@
 	public function send_pingback( $source_uri, $target_uri, $post = NULL )
 	{
 		// RemoteRequest makes it easier to retrieve the headers.
-		$rr = new RemoteRequest( $target_uri );
-		$rr->execute();
-		if ( ! $rr->executed() ) {
-			return false;
+		try {
+			$rr = new RemoteRequest( $target_uri );
+			$rr->execute();
+			if ( ! $rr->executed() ) {
+				return false;
+			}
 		}
+		catch ( Exception $e ) {
+			throw new XMLRPCException( -32300 );
+		}
 
 		$headers = $rr->get_response_headers();
 		$body = $rr->get_response_body();
Reply all
Reply to author
Forward
0 new messages