From 07a813a02ffcf8999802cece27ee5278c140760d Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Mon, 30 Oct 2023 14:22:46 +0000 Subject: [PATCH] fix: exceptions now has message in dictionary Added tests to check for the messages. --- supafunc/errors.py | 1 + tests/_async/test_function_client.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/supafunc/errors.py b/supafunc/errors.py index 1492abd..ced5f31 100644 --- a/supafunc/errors.py +++ b/supafunc/errors.py @@ -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 diff --git a/tests/_async/test_function_client.py b/tests/_async/test_function_client.py index 3a2378b..ef7a0e8 100644 --- a/tests/_async/test_function_client.py +++ b/tests/_async/test_function_client.py @@ -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!"