Skip to content

Conversation

@abaksy
Copy link
Contributor

@abaksy abaksy commented Jul 13, 2025

Use custom exceptions to handle all errors thrown by PESUAcademy-related functionality in app/pesu.py. The custom exceptions are derived from the base PESUAuthError class in app/exceptions/base.py. For now all usable exceptions are in app/exceptions/exceptions.py with the option of splitting each into its own file later on if required.

Copy link
Member

@aditeyabaral aditeyabaral left a comment

Choose a reason for hiding this comment

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

We should catch parsing errors in get_profile_informaiton. If the website changes layout, then this part will silently fail without information.

@abaksy abaksy requested a review from aditeyabaral July 13, 2025 20:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements custom exceptions for handling all errors in PESUAcademy-related functionality, replacing generic error handling with structured exception types derived from a base PESUAcademyError class.

  • Introduces authentication-specific exceptions (AuthenticationError, CSRFTokenError, ProfileFetchError, ProfileParseError)
  • Refactors error handling in app/pesu.py to use structured exceptions instead of generic Exception types
  • Updates tests to expect the new exception types and adjusts response format assertions

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/exceptions/base.py Defines the base PESUAcademyError exception class with message and status code
app/exceptions/authentication.py Implements specific authentication-related exception classes
app/pesu.py Refactors error handling to use custom exceptions instead of generic ones
app/app.py Adds exception handler for PESUAcademyError and updates error response format
tests/ Updates test assertions to expect new exception types and response formats
Comments suppressed due to low confidence (4)

app/exceptions/base.py:1

  • The class name 'PESUAcademyError' is inconsistent with the PR description which mentions 'PESUAuthError' as the base class.
class PESUAcademyError(Exception):

tests/unit/test_pesu.py:18

  • The test expects ProfileFetchError to be raised but still tries to assert on the result. Since an exception is expected, the result assignment and assertions on lines 19-20 are unreachable and should be removed.
        result = pesu.get_profile_information(MagicMock(), "testuser")

tests/unit/test_pesu.py:29

  • Similar to the previous test, this code tries to access result after expecting an exception. Lines 30-31 are unreachable and should be removed.
        result = pesu.get_profile_information(MagicMock(), "testuser")

tests/unit/test_pesu.py:40

  • This test expects CSRFTokenError but still asserts on result. Lines 41-42 are unreachable after the exception is raised and should be removed.
        result = pesu.authenticate("testuser", "testpass")

@abaksy abaksy merged commit 3a88378 into pesu-dev:main Jul 21, 2025
10 of 11 checks passed
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