Skip to content

Commit f34be05

Browse files
Preserve zero status codes in HyperbrowserError formatting
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 99d0760 commit f34be05

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

hyperbrowser/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __str__(self) -> str:
2121
"""Custom string representation to show a cleaner error message"""
2222
parts = [f"{self.args[0]}"]
2323

24-
if self.status_code:
24+
if self.status_code is not None:
2525
parts.append(f"Status: {self.status_code}")
2626

2727
if self.original_error and not isinstance(

tests/test_exceptions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from hyperbrowser.exceptions import HyperbrowserError
2+
3+
4+
def test_hyperbrowser_error_str_includes_zero_status_code():
5+
error = HyperbrowserError("request failed", status_code=0)
6+
7+
assert str(error) == "request failed - Status: 0"
8+
9+
10+
def test_hyperbrowser_error_str_includes_original_error_details_once():
11+
root_cause = ValueError("boom")
12+
error = HyperbrowserError("request failed", original_error=root_cause)
13+
14+
assert str(error) == "request failed - Caused by ValueError: boom"

0 commit comments

Comments
 (0)