Skip to content

Commit a74ed0a

Browse files
authored
fix: return notice id from notify (#232)
Fixes #231
1 parent b7ba982 commit a74ed0a

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

honeybadger/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .utils import StringReprJSONEncoder
1010
from .types import EventsSendResult, EventsSendStatus
1111

12-
1312
logger = logging.getLogger(__name__)
1413

1514

honeybadger/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def _send_notice(self, notice):
4646

4747
if not isinstance(notice, Notice):
4848
logger.debug("Notice was filtered out by before_notify callback")
49-
return
49+
return None
5050

5151
if notice.excluded_exception():
5252
logger.debug("Notice was excluded by exception filter")
53-
return
53+
return None
5454

55-
self._connection().send_notice(self.config, notice)
55+
return self._connection().send_notice(self.config, notice)
5656

5757
def begin_request(self, _):
5858
error_context.clear()

honeybadger/tests/test_core.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,56 @@ def test_payload(request):
591591
hb.configure(api_key="aaa", force_report_data=True)
592592
# This should fail according to breaking change, but currently creates malformed payload
593593
hb.notify(error_message="Some error message", context={"foo": "bar"})
594+
595+
596+
def test_notify_returns_notice_id():
597+
"""Test that notify() returns a notice_id (UUID) when sending succeeds"""
598+
hb = Honeybadger()
599+
hb.configure(api_key="aaa", environment="production")
600+
601+
with patch(
602+
"honeybadger.connection.send_notice",
603+
return_value="test-notice-uuid-123",
604+
) as mock_send:
605+
result = hb.notify(
606+
error_class="Exception",
607+
error_message="Test message.",
608+
)
609+
610+
assert mock_send.call_count == 1
611+
assert result == "test-notice-uuid-123"
612+
613+
614+
def test_notify_returns_none_when_filtered_by_before_notify():
615+
"""Test that notify() returns None when before_notify filters out the notice"""
616+
617+
def before_notify(notice):
618+
return None # Filter out the notice
619+
620+
hb = Honeybadger()
621+
hb.configure(api_key="aaa", environment="production", before_notify=before_notify)
622+
623+
with patch("honeybadger.connection.send_notice") as mock_send:
624+
result = hb.notify(
625+
error_class="Exception",
626+
error_message="Test message.",
627+
)
628+
629+
assert mock_send.call_count == 0
630+
assert result is None
631+
632+
633+
def test_notify_returns_none_when_exception_excluded():
634+
"""Test that notify() returns None when the exception is excluded"""
635+
hb = Honeybadger()
636+
hb.configure(
637+
api_key="aaa",
638+
environment="production",
639+
excluded_exceptions=["ValueError"],
640+
)
641+
642+
with patch("honeybadger.connection.send_notice") as mock_send:
643+
result = hb.notify(ValueError("excluded error"))
644+
645+
assert mock_send.call_count == 0
646+
assert result is None

honeybadger/tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def mock_was_called(*args, **kwargs):
2323
) as request_mock:
2424
yield request_mock
2525
mock_called_event.wait(0.5)
26-
((request_object,), mock_kwargs) = request_mock.call_args
26+
(request_object,), mock_kwargs = request_mock.call_args
2727
func(request_object)
2828

2929

0 commit comments

Comments
 (0)