From 3ea310e4bbab32cf09cfa91a9d945e6e23d311db Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Sat, 6 Oct 2018 15:05:58 +0200 Subject: [PATCH] Do not return error id if we know we did not send the error --- lib/Raven/Client.php | 13 +++++++------ test/Raven/Tests/ClientTest.php | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 971a23340b..93435151f9 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -934,7 +934,9 @@ public function capture($data, $stack = null, $vars = null) $this->process($data); if (!$this->store_errors_for_bulk_send) { - $this->send($data); + if ($this->send($data) === false) { + return null; + } } else { $this->_pending_events[] = $data; } @@ -1032,21 +1034,20 @@ public function send(&$data) && call_user_func_array($this->send_callback, array(&$data)) === false ) { // if send_callback returns false, end native send - return; + return false; } if (!$this->server) { - return; + return false; } if ($this->transport) { - call_user_func($this->transport, $this, $data); - return; + return call_user_func($this->transport, $this, $data); } // should this event be sampled? if (rand(1, 100) / 100.0 > $this->sample_rate) { - return; + return false; } $message = $this->encode($data); diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 6d68467eba..0c128ce559 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -38,9 +38,14 @@ public function send(&$data) { if (is_callable($this->send_callback) && call_user_func_array($this->send_callback, array(&$data)) === false) { // if send_callback returns falsely, end native send - return; + return false; } + $this->__sent_events[] = $data; + + if (!$this->server) { + return false; + } } public static function is_http_request() @@ -1337,11 +1342,21 @@ public function testCaptureLastError() */ public function testGetLastEventID() { - $client = new Dummy_Raven_Client(); + $client = new Dummy_Raven_Client('http://public:secret@example.com/1'); $client->capture(array('message' => 'test', 'event_id' => 'abc')); $this->assertEquals('abc', $client->getLastEventID()); } + /** + * @covers Raven_Client::getLastEventID + */ + public function testGetLastEventIDWithoutServer() + { + $client = new Dummy_Raven_Client(); + $client->capture(array('message' => 'test', 'event_id' => 'abc')); + $this->assertEquals(null, $client->getLastEventID()); + } + /** * @covers Raven_Client::setTransport */