diff --git a/supabase_functions/_async/functions_client.py b/supabase_functions/_async/functions_client.py index 42d8d20..ba12dbb 100644 --- a/supabase_functions/_async/functions_client.py +++ b/supabase_functions/_async/functions_client.py @@ -54,9 +54,14 @@ async def _request( try: response.raise_for_status() except HTTPError as exc: + status_code = None + if hasattr(response, "status_code"): + status_code = response.status_code + raise FunctionsHttpError( response.json().get("error") - or f"An error occurred while requesting your edge function at {exc.request.url!r}." + or f"An error occurred while requesting your edge function at {exc.request.url!r}.", + status_code, ) from exc return response diff --git a/supabase_functions/_sync/functions_client.py b/supabase_functions/_sync/functions_client.py index 99780eb..d8a410f 100644 --- a/supabase_functions/_sync/functions_client.py +++ b/supabase_functions/_sync/functions_client.py @@ -54,9 +54,14 @@ def _request( try: response.raise_for_status() except HTTPError as exc: + status_code = None + if hasattr(response, "status_code"): + status_code = response.status_code + raise FunctionsHttpError( response.json().get("error") - or f"An error occurred while requesting your edge function at {exc.request.url!r}." + or f"An error occurred while requesting your edge function at {exc.request.url!r}.", + status_code, ) from exc return response diff --git a/supabase_functions/errors.py b/supabase_functions/errors.py index ced5f31..0529e34 100644 --- a/supabase_functions/errors.py +++ b/supabase_functions/errors.py @@ -25,20 +25,20 @@ def to_dict(self) -> FunctionsApiErrorDict: class FunctionsHttpError(FunctionsError): - def __init__(self, message: str) -> None: + def __init__(self, message: str, code: int | None = None) -> None: super().__init__( message, "FunctionsHttpError", - 400, + 400 if code is None else code, ) class FunctionsRelayError(FunctionsError): """Base exception for relay errors.""" - def __init__(self, message: str) -> None: + def __init__(self, message: str, code: int | None = None) -> None: super().__init__( message, "FunctionsRelayError", - 400, + 400 if code is None else code, )