Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions library/Zend/Soap/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 @@ -993,6 +998,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 @@ -1009,6 +1023,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 tests/ZendTest/Soap/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,15 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype()
$this->assertContains('Invalid XML', $response->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());
}
}