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

feat: add error codes #556

Merged
merged 8 commits into from
Aug 16, 2024
Merged

feat: add error codes #556

merged 8 commits into from
Aug 16, 2024

Conversation

silentworks
Copy link
Contributor

@silentworks silentworks commented Jul 30, 2024

What kind of change does this PR introduce?

Adds support for error codes. All AuthError descendants will now have a code property which will encode (when present and supported by the server) the reason why the error occurred.

What is the current behavior?

No error codes in AuthError

What is the new behavior?

Error codes in AuthError

Additional context

In relation to:
supabase/auth#1377
supabase/auth-js#855
supabase/auth#915

@silentworks silentworks linked an issue Jul 30, 2024 that may be closed by this pull request
@silentworks silentworks changed the title add error codes feat: add error codes Jul 30, 2024
@@ -97,6 +98,8 @@ def _request(
) -> Union[T, None]:
url = f"{self._url}/{path}"
headers = {**self._headers, **(headers or {})}
if headers.get(API_VERSION_HEADER_NAME) is None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect. If there's no API_VERSION_HEADER_NAME the server is probably on an old version (or potentially CORS misconfigured). In that case the default shouldn't be 2024-01-01 but rather the initial unspecified API version.

You can represent this as 1970-01-01 or something equivalent to it. None is fine too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the equivalent of what's in the JS library https://github.com/supabase/auth-js/blob/master/src/lib/fetch.ts#L137-L139, so is the JS library code incorrect?

data = error.response.json()

error_code = None
response_api_version = parse_response_api_version(error.response)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this parse_response_api_version should return Unix timestamp 0 and your code below will magically work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here? If I put 0 just as with the JS library it will fall through to the second part of the if statement which is the elif. Can you elaborate more so that it's clear what could go wrong here please?

supabase_auth/helpers.py Outdated Show resolved Hide resolved
Copy link
Contributor

@juancarlospaco juancarlospaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@juancarlospaco juancarlospaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@silentworks silentworks merged commit 05dfb8a into main Aug 16, 2024
8 checks passed
@silentworks silentworks deleted the silentworks/error-codes branch August 16, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add error codes to the auth library
4 participants