Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5810 from lilobase/Soa…
Browse files Browse the repository at this point in the history
…pServerCaughtException

[Zend\Soap\Server] Add getException to get caught exceptions

Conflicts:
	tests/ZendTest/Soap/ServerTest.php
  • Loading branch information
weierophinney committed Mar 4, 2014
2 parents 743493a + b2e6c04 commit 5eeaa8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Server implements ZendServerServer
*/
protected $faultExceptions = array();

/**
* Container for caught exception during business code execution
* @var \Exception
*/
protected $caughtException = null;
/**
* SOAP Server Features
* @var int
Expand Down Expand Up @@ -1014,6 +1019,15 @@ public function getFaultExceptions()
return $this->faultExceptions;
}

/**
* Return caught exception during business code execution
* @return null|\Exception caught exception
*/
public function getException()
{
return $this->caughtException;
}

/**
* Generate a server fault
*
Expand All @@ -1030,6 +1044,8 @@ public function getFaultExceptions()
*/
public function fault($fault = null, $code = 'Receiver')
{
$this->caughtException = (is_string($fault)) ? new \Exception($fault) : $fault;

if ($fault instanceof \Exception) {
if ($this->isRegisteredAsFaultException($fault)) {
$message = $fault->getMessage();
Expand Down
11 changes: 11 additions & 0 deletions test/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,4 +948,15 @@ public function testDebugMode()
$this->assertEquals('test', $afterDebug->getMessage());
}

public function testGetOriginalCaughtException()
{
$server = new Server();
$fault = $server->fault(new \Exception('test'));

$exception = $server->getException();
$this->assertInstanceOf('\Exception', $exception);
$this->assertEquals('test', $exception->getMessage());
$this->assertInstanceOf('\SoapFault', $fault);
$this->assertEquals('Unknown error', $fault->getMessage());
}
}

0 comments on commit 5eeaa8b

Please sign in to comment.