From 1768481f059ca6bb559b41481cf76d79b8fc6cc1 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Fri, 6 Aug 2010 07:22:17 +0000
Subject: [PATCH] SimpleSAML_Error_Exception: Add fromException().

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2484 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Error/Exception.php | 20 ++++++++++++++++----
 modules/metarefresh/www/fetch.php  |  4 +---
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/SimpleSAML/Error/Exception.php b/lib/SimpleSAML/Error/Exception.php
index fb8b62a1c..761665ae3 100644
--- a/lib/SimpleSAML/Error/Exception.php
+++ b/lib/SimpleSAML/Error/Exception.php
@@ -49,11 +49,23 @@ class SimpleSAML_Error_Exception extends Exception {
 		$this->backtrace = SimpleSAML_Utilities::buildBacktrace($this);
 
 		if ($cause !== NULL) {
-			if (!($cause instanceof SimpleSAML_Error_Exception)) {
-				$cause = new SimpleSAML_Error_UnserializableException($cause);
-			}
-			$this->cause = $cause;
+			$this->cause = SimpleSAML_Error_Exception::fromException($cause);
+		}
+	}
+
+
+	/**
+	 * Convert any exception into a SimpleSAML_Error_Exception.
+	 *
+	 * @param Exception $e  The exception.
+	 * @return SimpleSAML_Error_Exception  The new exception.
+	 */
+	public static function fromException(Exception $e) {
+
+		if ($e instanceof SimpleSAML_Error_Exception) {
+			return $e;
 		}
+		return new SimpleSAML_Error_UnserializableException($e);
 	}
 
 
diff --git a/modules/metarefresh/www/fetch.php b/modules/metarefresh/www/fetch.php
index 70f0ba009..f268cb9fc 100644
--- a/modules/metarefresh/www/fetch.php
+++ b/modules/metarefresh/www/fetch.php
@@ -44,9 +44,7 @@ foreach ($sets AS $setkey => $set) {
 				break;
 		}
 	} catch (Exception $e) {
-		if (! $e instanceof SimpleSAML_Error_Exception) {
-			$e = new SimpleSAML_Error_UnserializableException($e);
-		}
+		$e = SimpleSAML_Error_Exception::fromException($e);
 		$e->logWarning();
 	}
 	
-- 
GitLab