ai-cfia / membrane-backend

Membrane Backend: A centralized authentication service for Single Sign-On (SSO) enabling seamless token-based email verification across multiple client applications.
MIT License
1 stars 0 forks source link

Refactor app.py for Enhanced Error Handling and JWT Processing #10

Closed CFIALeronB closed 1 year ago

CFIALeronB commented 1 year ago

Description:

We've identified several areas within app.py that can benefit from refactoring for improved error handling, JWT token processing, and overall code maintainability.

Tasks/Changes Needed:

  1. Consolidate Exception Imports:

     Combine and simplify exception handling.
     Introduce umbrella exceptions like JWTError and RequestError.
  2. Streamline JWT Token Handling in /login Route:

     Merge individual try-except blocks.
     Introduce extract_and_validate_request_data function to handle email and redirect URL processing.
  3. Improve Error Responses in /verify_token Route: Consolidate exception handling for MissingTokenError, InvalidTokenError, and jwt_exceptions.InvalidTokenError. Ensure error messages are concise and user-friendly.

  4. Refactor Imports: Remove redundant or unused imports. Reorganize the remaining imports for clarity.

  5. Add Tests: Write tests for the new functions and exceptions. Ensure tests cover edge cases and potential error scenarios.