From 067398e8216d7de9d6c509ebf932febd6f67c8ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no>
Date: Sat, 2 Jul 2016 17:22:43 +0200
Subject: [PATCH] Add an optional parameter to
 SimpleSAML_Session::useTransientSession().

This way we can pass an exception that made us use transient sessions, and get the method to throw that exception after getting the transient session.
---
 lib/SimpleSAML/Session.php | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/SimpleSAML/Session.php b/lib/SimpleSAML/Session.php
index 7f482a651..241b70578 100644
--- a/lib/SimpleSAML/Session.php
+++ b/lib/SimpleSAML/Session.php
@@ -324,8 +324,11 @@ class SimpleSAML_Session
      *
      * Create a session that should not be saved at the end of the request.
      * Subsequent calls to getInstance() will return this transient session.
+     *
+     * @param Exception|null $exception An exception that made us use a transient session. Specify if you want to log a
+     * message and that exception being thrown after loading the transient session.
      */
-    public static function useTransientSession()
+    public static function useTransientSession($exception = null)
     {
         if (isset(self::$instance)) {
             // we already have a session, don't bother with a transient session
@@ -333,6 +336,16 @@ class SimpleSAML_Session
         }
 
         self::load(new SimpleSAML_Session(true));
+
+        if ($exception instanceof Exception) {
+            if ($exception instanceof SimpleSAML_Error_Exception) {
+                $cause = $exception->getCause();
+                if ($cause instanceof Exception) {
+                    throw $cause;
+                }
+            }
+            throw $exception;
+        }
     }
 
     /**
-- 
GitLab