Skip to content
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

fix: custom error status code from edge function returned correctly #196

Merged
merged 1 commit into from
Mar 26, 2025
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
7 changes: 6 additions & 1 deletion supabase_functions/_async/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion supabase_functions/_sync/functions_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions supabase_functions/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)