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

login: bubble up LdbError so that it can be handled better #26

Merged
merged 4 commits into from
Mar 9, 2024

Conversation

robvdl
Copy link
Member

@robvdl robvdl commented Mar 8, 2024

Step one is to change connect_samdb, also placing host as the first argument for consistency.

connect_samdb now expects host, username and password to be strings and won't do checking itself anymore if they are present.

It will no longer catch LdbError in connect_samdb either and just let it raise instead. This is so that it can be handled further up the chain.

In get_samdb, which provides the request.samdb property, we keep the return type as Optional[SamDB], but only return None if there are no credentials in the session at all (it raises KeyError).

If the credentials in the session worked before, but now no longer work, for example server is gone, just let it raise LdbError in get_samdb because we need to know at this point when that happens rather than return None (which means not authenticated).

@robvdl robvdl force-pushed the bubble-up-exceptions branch from 8cf5884 to ad667d4 Compare March 8, 2024 22:22
robvdl added 4 commits March 9, 2024 13:57
Step one is to change connect_samdb, also placing host as the first argument for consistency.

connect_samdb now expects host, username and password to be strings and won't do checking itself anymore if they are present.

It will no longer catch LdbError in connect_samdb either and just let it raise instead. This is so that it can be handled further up the chain.

In get_samdb, which provides the request.samdb property, we keep the return type as Optional[SamDB], but only return None if there are no credentials in the session at all (it raises KeyError).

If the credentials in the session worked before, but now no longer work, for example server is gone, just let it raise LdbError in get_samdb because we need to know at this point when that happens rather than return None (which means not authenticated).
Step two bubble it all the way upto the login view in views/auth.py and handle the message returned from the LdbError exception.
@robvdl robvdl force-pushed the bubble-up-exceptions branch from 7e3dddc to 351d837 Compare March 9, 2024 00:58
@robvdl robvdl merged commit 2153184 into master Mar 9, 2024
1 check passed
@robvdl robvdl deleted the bubble-up-exceptions branch March 9, 2024 00:59
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.

1 participant