Skip to content

Commit

Permalink
* added extradata param on notify exception, useful in some case.
Browse files Browse the repository at this point in the history
 * updated README
  • Loading branch information
francois2metz committed Apr 1, 2010
1 parent 02984d0 commit 3a1ce93
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
17 changes: 13 additions & 4 deletions README.rst
Expand Up @@ -16,9 +16,18 @@ Usage

::

$e = new Services_ErrorNot('http://example.net/', 'my-api-key');
$e->notify('big error');
$e->notify('big error', '2010-03-03T00:00:42+01:00');
$errornot = new Services_ErrorNot('http://example.net/', 'my-api-key');
$errornot->notify('big error');
$errornot->notify('big error', '2010-03-03T00:00:42+01:00');
try
{

}
catch (MyException $e)
{
errornot->notifyException($e); // send specific exception
errornot->notifyException($e, 'foo'); // send specific exception with extra data
}

ErrorNot can install a custom exception handler:

Expand Down Expand Up @@ -59,7 +68,7 @@ TESTS
$> php tests/test_errornot.php
test_errornot.php
OK
Test cases run: 2/2, Passes: 8, Failures: 0, Exceptions: 0
Test cases run: 2/2, Passes: 16, Failures: 0, Exceptions: 0


Author
Expand Down
8 changes: 5 additions & 3 deletions errornot.php
Expand Up @@ -65,15 +65,17 @@ public function setNetworkAdapter(HTTP_Request2_Adapter $http_request2_adapter)
/**
* Notify Exception
* @param Exception $exception
* @params mixed $extradata optional extra data
*/
public function notifyException(Exception $exception)
public function notifyException(Exception $exception, $extradata = null)
{
$data = array('extra' => $extradata);
isset($_SESSION) ? $data['session'] = $_SESSION : '';
$this->notify($exception->getMessage(),
null, // auto now
$exception->getTrace(),
array('params' => array('post' => $_POST, 'get' => $_GET, 'cookies' => $_COOKIE)),
$_SERVER,
isset($_SESSION) ? $_SESSION : '');
$_SERVER, $data);
if (!is_null($this->previous_exception_handler))
{
call_user_func($this->previous_exception_handler, $exception);
Expand Down
14 changes: 13 additions & 1 deletion tests/test_errornot.php
Expand Up @@ -59,7 +59,7 @@ public function testPostExtraParams()
'&error[data][0]=mydata1&error[data][1]=mydata2', urldecode($mock_network->getRequest()->getBody()));
}

public function testNotifyExceptionWithEnvironment()
public function testNotifyException()
{
list($errornot, $mock_network) = $this->createMockRequest();
try {
Expand All @@ -69,6 +69,18 @@ public function testNotifyExceptionWithEnvironment()
}
$this->assertNotNull($mock_network->getRequest());
}

public function testNotifyExceptionWithData()
{
$_SERVER = array();
list($errornot, $mock_network) = $this->createMockRequest();
try {
throw new Exception('message exception');
} catch (Exception $e) {
$errornot->notifyException($e, 'foo');
}
$this->assertPattern('/error\[data\]\[extra\]=foo$/', urldecode($mock_network->getRequest()->getBody()));
}
}

class TestErrorNotExceptionHandler extends UnitTestCase
Expand Down

0 comments on commit 3a1ce93

Please sign in to comment.