Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

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
) -> 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?

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 force-pushed the silentworks/error-codes branch from 707c176 to cbbcd06 Compare August 16, 2024 10:53
@silentworks silentworks force-pushed the silentworks/error-codes branch from 8b4dbb5 to 7f67ffd Compare August 16, 2024 11:35
@silentworks silentworks merged commit 05dfb8a into main Aug 16, 2024
@silentworks silentworks deleted the silentworks/error-codes branch August 16, 2024 12:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add error codes to the auth library

5 participants