Skip to content

Commit

Permalink
If no string representation, print generic error message
Browse files Browse the repository at this point in the history
  • Loading branch information
rpdelaney committed Dec 12, 2023
1 parent 3d1c1dc commit f78b5ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion downforeveryone/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def isitup(url: str) -> Tuple[str, int]:
return "Network timeout.", 3
except RequestException as rexc:
title = type(rexc).__name__
message = str(rexc)
message = str(rexc) if str(rexc) else "Unexpected error occurred."
return (f"{title}: {message}"), 3

if response.status_code != HTTPStatus.OK.value:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_isup/test_is_it_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ def test_isup_handles_request_exception(fake_response_args):
assert result_status == 3


@responses.activate
def test_isup_handles_empty_request_exception(fake_response_args):
exc = RequestException()
fake_response_args["body"] = exc

responses.add(**fake_response_args)

result_message, result_status = isup.isitup(__TEST_URL__)

assert result_message == "RequestException: Unexpected error occurred."
assert result_status == 3


@responses.activate
def test_isup_handles_timeout_exception():
responses.add(
Expand Down

0 comments on commit f78b5ae

Please sign in to comment.