Skip to content

fix: exceptions now has message in dictionary #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions supafunc/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FunctionsApiErrorDict(TypedDict):
class FunctionsError(Exception):
def __init__(self, message: str, name: str, status: int) -> None:
super().__init__(message)
self.message = message
self.name = name
self.status = status

Expand Down
14 changes: 13 additions & 1 deletion tests/_async/test_function_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,17 @@ async def test_invoke_with_non_200_response():
return_value=Response(404),
side_effect=FunctionsHttpError("Http error!"),
)
with pytest.raises(FunctionsHttpError, match=r"Http error!"):
with pytest.raises(FunctionsHttpError, match=r"Http error!") as exc:
await function_client().invoke(function_name="hello-world")
assert exc.value.message == "Http error!"


async def test_relay_error_message():
async with respx.mock:
respx.post(f"{FUNCTIONS_URL}/hello-world").mock(
return_value=Response(200, headers={"x-relay-header": "true"}),
side_effect=FunctionsRelayError("Relay error!"),
)
with pytest.raises(FunctionsRelayError, match=r"Relay error!") as exc:
await function_client().invoke(function_name="hello-world")
assert exc.value.message == "Relay error!"