Skip to content

Commit

Permalink
Add extra logging for Moodle's file check
Browse files Browse the repository at this point in the history
We are seeing a school response that doesn't seem to contain the
content type header we rely on to determine if a file still exists in
Moodle.

Before we try alternative approaches to detect if a file exists lets
add some logging to check the response headers.

One possible explanation could be that we are dealing with two different
issues issues:

- The server doesn't return the content type header for this request

Maybe a different Moodle version? Some server configured in front of
Moodle strips them.

- The file doesn't exist on the server or we can access it for some
  reason.
  • Loading branch information
marcospri committed Nov 4, 2024
1 parent 6e8fc6f commit 9d6c98f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lms/services/moodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from lms.services.aes import AESService
from lms.services.exceptions import ExternalRequestError
from lms.services.http import HTTPService
import logging

LOG = logging.getLogger(__name__)


class Function(StrEnum):
Expand Down Expand Up @@ -139,6 +142,8 @@ def file_exists(self, file_id) -> bool:
# We don't want to download the full file so we'll do a HEAD request and assume:
# - JSON response, it's an error response
# - Anything else, it's the file we are after

LOG.info("Headers from Moodle file check %s", response.headers)
return not response.headers["content-type"].startswith("application/json")

def page(self, course_id, page_id) -> dict | None:
Expand Down

0 comments on commit 9d6c98f

Please sign in to comment.