Skip to content

Commit 7a0fee7

Browse files
authored
expose the current running exception to user code
In case of exception during pipe exception, it will be stored and make available to user code using the `getRunningException` function. It is intended to be used in middlewares (in beforeSend hook) or in the error handlers. This change has been done in the least intrusive way possible : - it is completely backward compatible - there are no change in middle wares nor error handler signatures
1 parent 8e651cf commit 7a0fee7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/WaterPipe/WaterPipe.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ class WaterPipe
154154
*/
155155
private $_mapRegistry;
156156

157+
/**
158+
* In case an exception occures during pipe execution, it will be
159+
* stored here for user code to read in middlewares and errorhandlers
160+
*
161+
* @var Exception
162+
*/
163+
private $_runningException;
164+
157165
/**
158166
* @return WaterPipe
159167
*/
@@ -206,6 +214,7 @@ public function __construct()
206214
$this->_errorsRegistry = array();
207215
$this->_pipesRegistry = array();
208216
$this->_mapRegistry = array();
217+
$this->_runningException = null;
209218
}
210219

211220
/**
@@ -430,6 +439,15 @@ public function run()
430439
$pipe[1]->_runBase($pipe[0]);
431440
}
432441
}
442+
443+
/**
444+
* If an exception has occured while running the pipe
445+
* This method will return that exception.
446+
* Otherwise, will return null.
447+
*/
448+
function getRunningException () {
449+
return $this->_runningException;
450+
}
433451

434452
/**
435453
* @param string $baseUri
@@ -546,6 +564,8 @@ private function _executeRequest()
546564
// NOTE: No code will be executed after this call...
547565
$this->_executeAction($runner);
548566
} catch (\Exception $e) {
567+
$this->_runningException = $e;
568+
549569
if (isset($this->_errorsRegistry[500])) {
550570
$this->_executeAction($this->_errorsRegistry[500]);
551571
} else {

0 commit comments

Comments
 (0)