Skip to content

Commit

Permalink
fix: exceptions now has message in dictionary (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Smith authored Oct 30, 2023
2 parents 4e18712 + 07a813a commit 7273927
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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!"

0 comments on commit 7273927

Please sign in to comment.