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: exceptions for auth errors 400, 401, 403 #230

Merged
merged 4 commits into from
Feb 24, 2025

Conversation

davidhuser
Copy link
Contributor

related to #229

  • introduce new exceptions including a factory to assign exceptions based on starlette.request type (http or websocket)
  • updated the contributor guide
  • fixed a minor mypy issue preventing pre-commit

@davidhuser
Copy link
Contributor Author

davidhuser commented Feb 11, 2025

failing linting tests in demo_project but these seem unrelated to this PR. How should we proceed?

@davidhuser davidhuser changed the title feat: differentiating between error codes feat: exceptions for auth errors 400, 401, 403 Feb 11, 2025
@JonasKs
Copy link
Member

JonasKs commented Feb 12, 2025

I really like this, thanks!! I have some concerns about backwards compatibility, since I'd prefer not to major bump again 😁 Could we ensure that the old InvalidAuthHttp is a base? So anyone importing it, or catching it, will still catch all exceptions?

Something like this, I think would work?

class InvalidAuth(HTTPException):
    ...

class ForbiddenHttp(InvalidAuth, HTTPException):
    ...

failing linting tests in demo_project but these seem unrelated to this PR. How should we proceed?

Ignore. I'll look into this another time. It won't block merge 😊

@davidhuser
Copy link
Contributor Author

davidhuser commented Feb 12, 2025

Ah sure, compatibility was not on my radar. I liked your implementation idea but we would change the interface of InvalidAuth from a factory function to a class, so I thought to keep it as a factory but routing it to the new exceptions instead, example below... wdyt?

# old InvalidAuth
def InvalidAuth(detail: str, request: HTTPConnection) -> UnauthorizedHttp | UnauthorizedWebSocket:
    if request.scope['type'] == 'http':
        return UnauthorizedHttp(detail) # new exception
    return UnauthorizedWebSocket(detail) # new exception

I also tried to add a new test module specific to this.

And I added markers / TODO for the v6.0.0 release, not sure if ok!

@JonasKs
Copy link
Member

JonasKs commented Feb 20, 2025

Hey @davidhuser , so sorry for the lack of review - I'll get it done this weekend. First look looks good though, same with your implementation around exceptions and backwards compatibility! 😊

Copy link
Member

@JonasKs JonasKs left a comment

Choose a reason for hiding this comment

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

Looks very good. Thanks for also fixing CONTRIBUTING.md!! 😊

@JonasKs JonasKs merged commit 8ef26ee into intility:main Feb 24, 2025
8 of 10 checks passed
@davidhuser davidhuser deleted the feat/229-error-codes branch February 24, 2025 11:57
@JonasKs
Copy link
Member

JonasKs commented Feb 24, 2025

I've created a new release. Thanks again for all the effort you've put into helping me out with this library!

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.

2 participants