Skip to content

Commit

Permalink
Update ex_fetch_courses to handle forbidden error
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacob committed Aug 12, 2024
1 parent d300218 commit f6a98b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.1] - 2024-08-12

### Changed
- Extended method `ex_fetch_courses` now detects a 403 response
- The package-wide logger is now public

### Added
- Logging was added to the extended api module

## [0.3.0] - 2024-08-11

### Added
Expand Down
4 changes: 2 additions & 2 deletions blackboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

__all__ = ['BlackboardSession']

_logger = logging.getLogger(__name__)
_logger.addHandler(logging.NullHandler())
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
25 changes: 11 additions & 14 deletions blackboard/api_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import logging
from typing import Any

from .blackboard import BBCourse
from .api import BlackboardSession
from .filters import BBMembershipFilter
from .exceptions import BBForbiddenError

logger = logging.getLogger(__name__)


class BlackboardExtended(BlackboardSession):
Expand All @@ -47,22 +51,15 @@ def ex_fetch_courses(self, *,

for ms in memberships:
if ms.availability:
private = False

assert ms.courseId is not None

try:
course = self.fetch_courses(course_id=ms.courseId)
except ValueError as e: # soon to change
private = str(e) == 'Private course'
# log please
raise e

# mypy does not know result of calling API
assert isinstance(course, BBCourse)
course = course.model_copy(update={'created': ms.created})

if not private:
except BBForbiddenError:
logger.warning(f"Course {ms.courseId} is not available")
pass
else:
# mypy does not know result of calling API
assert isinstance(course, BBCourse)
course = course.model_copy(update={'created': ms.created})
courses.append(course)

return courses

0 comments on commit f6a98b3

Please sign in to comment.